I have searched but could not find any articles on how to check if youtube videos exist using youtube api and objective-c how can this be done in code?
I have tried this but i keep getting an Error 400 back 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];
}
}
}];
You should request to this URL
https://www.googleapis.com/youtube/v3/videos?part=status&id=%@&key=%@,yourVideoId,yourYoutubeAPIKey
After request this URL you will get some 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;
};
}
This is the response json from 2 videos
You will see in 2 json, the different is uploadStatus (one is processed and one is rejected).
This field will let you know which youtube video is available. And there are 5 values for uploadStatus:
deleted, failed, processed, rejected, uploaded
NSString *videoStatus = [responseJson[@"items"] objectAtIndex:0][@"status"][@"uploadStatus"];
if([videoStatus isEqualToString:@"deleted"] || [videoStatusisEqualToString:@"failed"] || [videoStatus isEqualToString:@"rejected"]){
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With