我無法獲取YouTube視頻的視頻網址。我可以使用縮略圖和標題檢索播放列表項目,但無法獲取實際的視頻網址。來自播放列表項目的YouTube Objective-C API視頻網址項目
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
service.APIKey = @"API Key";
GTLQueryYouTube *query = [GTLQueryYouTube queryForPlaylistItemsListWithPart:@"snippet,contentDetails"];
query.playlistId = @"playlist ID";
query.maxResults = 50;
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;
for (GTLYouTubeSearchResult *item in products)
{
NSLog(@"%@", item.snippet);
NSString *dictionary = [item.snippet JSONValueForKey:@"videoId"];
GTLYouTubeThumbnailDetails *thumbnails = item.snippet.thumbnails;
GTLYouTubeThumbnail *thumbnail = thumbnails.high;
NSString *thumbnailString = thumbnail.url;
if (thumbnailString != nil)
{
[self.thumbnailsArray addObject:thumbnailString];
[self.thumbnailTitleArray addObject:item.snippet.title];
//[self.videos addObject:video];
NSLog(@"id: %@", dictionary);
}
}
}
else
{
NSLog(@"Error: %@", error.description);
}
[self.tableView reloadData];
}];
有誰知道如何使用YouTube API獲取視頻網址?
工作很好!我只需要將item.id.videoId更改爲item.identifier.videoId。感謝您的答覆! :d –