Youtube Api, How To Parse All Vids With A Nextpagetoken?
I'm using Node.JS, and the 'request' library https://github.com/request/request I read the documentation, as much as I can request only 50 videos from the channel, in response from
Solution 1:
Typically when dealing with API's its not fair to use a for loop, you may want to step through your requests slower. My below example uses simple recursion but you may want to even add a timeout when the function calls itself.
let url = 'formatted url'let videos = [];
function worker = (token, url) {
  
  //use the standard url if there is no tokenif (!token) {
    request({url:url}, function(err, response, body){
      let data = JSON.parse(body);
      //do something with data//if there is a next page token run worker again.if (data.nextPageToken) {
        let token = data.nexPageToken;
        
        returnworker(token, url);
      } else {
        console.log('fin');
      }
      
   } else {
     //if there is a token use a new urllet nurl = 'url + page token';
     
     request({url: url}, function(err, response, body) {
      
      let data = JSON.parse(body);
      //do something with data//if there is a token run the worker againif (data.nextPageToken) {
        let token = data.nextPageToken;
        returnworker(token, url);
      } else {
        console.log('fin');
      }
      
     })
     
   }
}
worker(null, url);
Post a Comment for "Youtube Api, How To Parse All Vids With A Nextpagetoken?"