我搜索过但找不到任何关于如何使用youtube api检查youtube视频是否存在的文章和目标-c如何在代码中完成?
我试过这个但是我一直从youtube上得到错误400:
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];
}
}
}];
答案 0 :(得分:2)
您应该请求此网址
https://www.googleapis.com/youtube/v3/videos?part=status&id=%@&key=%@,yourVideoId,yourYoutubeAPIKey
请求此URL后,您将获得一些json响应,如
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;
};
}
这是来自2个视频的响应json
您将在2 json中看到,不同的是 uploadStatus
(一个是processed
,一个是rejected
)。
此字段可让您知道哪些YouTube视频可用。 uploadStatus
有5个值:
已删除,失败,已处理,已拒绝,已上传
NSString *videoStatus = [responseJson[@"items"] objectAtIndex:0][@"status"][@"uploadStatus"];
if([videoStatus isEqualToString:@"deleted"] || [videoStatusisEqualToString:@"failed"] || [videoStatus isEqualToString:@"rejected"]){
}