title: YouTube API v3 request more items with nextPageToken (node.js)
body: <p>I'm trying to get more than 50 results using nextPageToken. I need to collect all the videos from a playlist or a channel and then pick random videos from the obtained list. The problem I encountered is that not all pages have 'nextPageToken' value (WHY?) therefore it won't let me get all videos.</p>
  
  <p>Here's my node file:</p>
  
  <pre><code>const request = require('request')
  var tokens = [];
  
  function getTokens(token) {
     var additions = "";
     if(token != "") additions = '&amp;pageToken='+token;
  
     request('https://www.googleapis.com/youtube/v3/search?part=snippet&amp;maxResults=30&amp;type=playlist&amp;channelId=CHANNEL-ID&amp;key=MY-KEY' + additions, function (error, response, body) {
        body = JSON.parse(body)
        if (!error &amp;&amp; response.statusCode == 200) {
            console.log(body.nextPageToken+"-"+body.items.length);
            getTokens(body.nextPageToken);
          }
     })
  };
  getTokens("");
  </code></pre>
  
  <p>OUTPUT RESULT: (there should be 800 total results, 30 results per page -> 26 tokens) as you can see, only 15 tokens are available:</p>
  
  <p><a href="https://i.stack.imgur.com/EDGS8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EDGS8.png" alt="List of tokens"></a></p>