YouTube Objective-C API视频maxResults

时间:2014-02-01 20:15:04

标签: ios objective-c ios7 youtube-api

我想知道传递视频maxResults的最佳方法。我不能把它设置为50岁。我现在需要获得大约207个视频。此列表将继续增长。

您对我将如何做到这一点有什么建议吗?

GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];

service.APIKey = @"API Key";
service.shouldFetchInBackground = YES;


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;
                                       GTLYouTubePlaylistItemListResponse *playlistItems = object;
                                       for (GTLYouTubeSearchResult *item in products)
                                       {
                                           GTLYouTubeThumbnailDetails *thumbnails = item.snippet.thumbnails;
                                           GTLYouTubeThumbnail *thumbnail = thumbnails.high;
                                           NSString *thumbnailString = thumbnail.url;
                                           if (thumbnailString != nil)
                                           {
                                               [self.thumbnailsURL addObject:thumbnailString];
                                               [self.thumbnailsArray addObject:thumbnailString];
                                               [self.thumbnailImages addObject:@"120x120@2x.png"];
                                               [self.thumbnailTitleArray addObject:item.snippet.title];
                                           }

                                       }
                                       for (GTLYouTubePlaylistItem *playlistItem in playlistItems)
                                       {
                                           GTLYouTubePlaylistItemContentDetails *details = playlistItem.contentDetails;
                                           [self.videos addObject:details.videoId];
                                       }
                                   }
                                   else
                                   {
                                       NSLog(@"Error: %@", error.description);
                                   }
                                   self.loading.hidden = YES;
                                   [self.tableView reloadData];
                               }];

提前感谢您的时间! :D

1 个答案:

答案 0 :(得分:1)

使用分页,您将获得其余结果。

YouTube API支持分页。您需要将nextPageToken作为pageToken放在下一个请求中,以获得下一页(在您的情况下为50)结果。

我的这2个答案应该对你有帮助:

page tokens use youtube api v3

Retrieve all videos from youtube playlist using youtube v3 API