1

I would like to know the best way to get passed the video maxResults. I can't set it past 50. I need to get about 207 videos right now. This list will continue to grow over time.

Do you have any suggestions on how I would do this?

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];
                               }];

Thank you in advance for your time! :D

PJ Vea
  • 112
  • 1
  • 9

1 Answers1

1

You'll get the rest of the results with using paging.

YouTube API supports pagination. You need to put your nextPageToken in your next request as pageToken to get the next page(50 in your case) of results.

These 2 answers of mine should help you:

page tokens use youtube api v3

Retrieve all videos from youtube playlist using youtube v3 API

Community
  • 1
  • 1
Ibrahim Ulukaya
  • 12,767
  • 1
  • 33
  • 36