Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Set Results Per Page For Google Node.js Youtube API v3 playlists.list() Method

$
0
0

I'm using the Google YouTube Api (v3) to fetch the video IDs for a YouTube Playlist. My code is working well enough, but I'd really like to set the "resultsPerPage" variable to a higher number. It is set to 5 by default. I'm using it for album tracks so most of the playlists that I'm working with are between 8 and 15 videos. It would be nice to get all of their info in one call.

When I execute the same request from the Google API Explorer there is no such limitation; it returns all of the videos in one response.

I tried setting the "resultsPerPage" option Node.js code that fetches the data, but that had no effect:

  const youtube_v3 = require('@googleapis/youtube').youtube_v3;  const youtube = new youtube_v3.Youtube();  const requestOptions = {    key: process.env.YOUTUBE_API_KEY,    part: 'snippet,contentDetails',    fields: 'items(snippet/title,contentDetails/videoId),pageInfo,nextPageToken',    playlistId: playlistId,    maxResult: maxResults,    resultsPerPage: 10 // this does nothing!  };  if ( pageToken ) {    requestOptions.pageToken = pageToken;  }  const results = await youtube.playlistItems.list( requestOptions );  const data = results.data;

I found some info in the Docs about a PageInfo class. It has a method named set_results_per_page() which seems promising. However, I have no idea how to access that class.

Has anyone managed to change the number of results per page using the API?


Viewing all articles
Browse latest Browse all 3831

Trending Articles