【问题标题】:YouTube Objective-C API video maxResultsYouTube Objective-C API 视频 maxResults
【发布时间】:2014-02-25 12:08:21
【问题描述】:

我想知道通过视频 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

【问题讨论】:

    标签: ios objective-c ios7 youtube-api


    【解决方案1】:

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

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

    我的这两个答案应该可以帮助你:

    page tokens use youtube api v3

    Retrieve all videos from youtube playlist using youtube v3 API

    【讨论】:

    • 感谢您的回复! :D
    猜你喜欢
    • 2014-05-14
    • 1970-01-01
    • 2013-07-12
    • 2013-03-07
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 2018-06-28
    • 2011-03-23
    相关资源
    最近更新 更多