以下のコードを使用して完全に機能しているクエリを使用して、単純にビデオを検索しようとしています。
// Create a service object for executing queries
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
// Services which do not require sign-in may need an API key from the
// API Console
service.APIKey = @"AIzaSyA-e4NldR2o8vYPpL6IcAcMH3HSnEpPPJY";
// Create a query
GTLQueryYouTube *query = [GTLQueryYouTube queryForSearchListWithPart:@"id,snippet"];
query.maxResults = 10;
query.q = searchBar.text;
query.videoEmbeddable = @"true";
query.type = @"video";
//query.country = @"US";
// Execute the query
GTLServiceTicket *ticket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
// This callback block is run when the fetch completes
if (error == nil) {
GTLYouTubeSearchListResponse *products = object;
[videoArray removeAllObjects];
// iteration of items and subscript access to items.
for (GTLYouTubeSearchResult *item in products) {
NSMutableDictionary *dictionary = [item JSONValueForKey:@"id"];
NSLog(@"%@", [dictionary objectForKey:@"videoId"]);
YoutubeVideo *video = [[YoutubeVideo alloc]init];
[video setLblTitle:item.snippet.title];
//Get youtube video image
[video setImgIconURL:[NSURL URLWithString:item.snippet.thumbnails.defaultProperty.url]];
[video setLblVideoURL:[dictionary objectForKey:@"videoId"]];
[video setLblChannelTitle:item.snippet.channelTitle];
[videoArray addObject:video];
}
reloadData = YES;
[tableView reloadData];
//Download images asynchronously
[NSThread detachNewThreadSelector:@selector(downloadImages)
toTarget:self
withObject:nil];
}else{
NSLog(@"Error: %@", error.description);
}
}];
ただし、ビデオに関する特定の情報を表示したいと思います。私が得ることができるこの情報のいくつか
item.snippet
ただし、動画の長さと再生回数も取得する必要があります。Youtube API 3.0 を使用してそれらを取得するにはどうすればよいですか?? これだけのために GData を使用するというアイデアもありましたが、使用するロード時間が文字通り 3 倍になります
NSString *JSONString = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://gdata.youtube.com/feeds/api/videos/%@?v=2&alt=json", [video lblVideoURL]]] encoding:NSUTF8StringEncoding error:nil ];
動画の長さと動画の再生回数を取得するにはどうすればよいですか?