IOS. Check if Youtube video exists using Youtube API.

I searched but couldn't find articles on how to check if youtube videos exist using youtube api and objective-c how can this be done in code?

EDIT

I tried this but I keep getting 400 error from youtube:

GDataQueryYouTube * query = [[GDataQueryYouTube alloc] init];

        query.feedURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.googleapis.com/youtube/v3/videos?id=%@", textFieldYoutube.text]];

        GDataServiceGoogleYouTube * service = [[GDataServiceGoogleYouTube alloc] init];

        service.userAgent = @"xxx";

        [service fetchFeedWithQuery:query
              completionHandler:^(GDataServiceTicket *ticket, GDataFeedBase *feed, NSError *error)
         {
             if(!error)
             {
             NSArray * entries = feed.entries;

             if(entries.count)
             {
                 GDataEntryYouTubeVideo * firstVideo = entries[0];
             }
             }

 }];

      

+3


source to share


1 answer


You must request this url

https://www.googleapis.com/youtube/v3/videos?part=status&id=%@&key=%@,yourVideoId,yourYoutubeAPIKey

      

After requesting this url, you will receive a json response like

    2016-08-10 11:14:44.157 YourApp[10127:86552] {
    etag = "\"I_8xdZu766_FSaexEaDXTIfEWc0/rBQu-ew0vFUVDl87HWqheTjFeZ4\"";
    items =     (
                {
            etag = "\"I_8xdZu766_FSaexEaDXTIfEWc0/qO4hLAd6uXnb116ECPtCa2RwNxM\"";
            id = zhDsNTmoENc;
            kind = "youtube#video";
            status =             {
                embeddable = 1;
                license = youtube;
                privacyStatus = public;
                publicStatsViewable = 1;
                uploadStatus = processed;
            };
        }
    );
    kind = "youtube#videoListResponse";
    pageInfo =     {
        resultsPerPage = 1;
        totalResults = 1;
    };
}

2016-08-10 11:14:44.153 YourApp[10127:86568] {
etag = "\"I_8xdZu766_FSaexEaDXTIfEWc0/OWcvT3ot9zyYa1s4P5GWh8yMPIQ\"";
items =     (
            {
        etag = "\"I_8xdZu766_FSaexEaDXTIfEWc0/NpmRcx9OpHgA2LoHqiki1KznNHc\"";
        id = HV4JYMQTsOU;
        kind = "youtube#video";
        status =             {
            embeddable = 1;
            license = youtube;
            privacyStatus = public;
            publicStatsViewable = 1;
            rejectionReason = length;
            uploadStatus = rejected;
        };
    }
);
kind = "youtube#videoListResponse";
pageInfo =     {
    resultsPerPage = 1;
    totalResults = 1;
};

      



}


You will see this json response from 2 videos in 2 json, another - (one - and one - ). This field will let you know which YouTube video is available. And there are 5 values ​​for : uploadStatus

processed

rejected


uploadStatus

deleted, not executed, processed, rejected, loaded

NSString *videoStatus = [responseJson[@"items"] objectAtIndex:0][@"status"][@"uploadStatus"];

if([videoStatus isEqualToString:@"deleted"] || [videoStatusisEqualToString:@"failed"] || [videoStatus isEqualToString:@"rejected"]){

}

      

+1


source







All Articles