Ios 播放列表项中的YouTube Objective-C API视频url

Ios 播放列表项中的YouTube Objective-C API视频url,ios,objective-c,ios7,youtube-api,Ios,Objective C,Ios7,Youtube Api,我无法获取YouTube视频的视频url。我可以检索带有缩略图和标题的播放列表项目,但无法获取实际的视频url GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init]; service.APIKey = @"API Key"; GTLQueryYouTube *query = [GTLQueryYouTube queryForPlaylistItemsListWithPart:@"snippet,contentDetails

我无法获取YouTube视频的视频url。我可以检索带有缩略图和标题的播放列表项目,但无法获取实际的视频url

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获取视频url吗?

v3 API中的不提供url。您可以改为将视频ID附加到字符串。播放页面URL的格式通常为:

   http://www.youtube.com/watch?v={VIDEO ID HERE}

首先,如果你只想在搜索结果中显示视频,你应该设置=video。 在代码中:

query.playlistId = @"playlist ID";
query.maxResults = 50;
query.type = @"video";
您需要在部件中添加“id”。您的查询电话将是:

GTLQueryYouTube *query = [GTLQueryYouTube queryForPlaylistItemsListWithPart:@"id,snippet,contentDetails"];
作为回应,您可以使用获取视频id。因此,在您的代码中,它将是:

NSString *videoId = item.identifier.videoId;
获得id后,可以将其插入:

http://www.youtube.com/watch?v={VIDEO ID HERE}

谢谢你的回答!:我在获取视频ID时也遇到了问题。它正在返回null。我可以看到resourceId JSON对象中的videoId。工作得很好!我只需要将item.id.videoId更改为item.identifier.videoId。谢谢你的回复!:D