machinepack-youtubenodemachines/youtubeAPICalls.js
function getVideoStatistics(auth, youtube, items, count, callback) {

  // Convert the video ID:s of the provided videos to the appropriate format
  var IDs = "";
  if (Array.isArray(items)) {
    for (var i = 0; i < items.length; i++) {
      if (i != 0) {
        IDs += ", "
      }
      IDs += items[i].id.videoId;
    }
  }

  youtube.videos.list( // Call the Youtube API
  {
    auth: auth,
    part: "statistics",
    id: IDs,
    maxResults: count //integer 0-50, default 5
  },
  function(err, res) {
    if (err) {
      console.log("The API returned an error: " + err);
    } else {
      var formatedVideos = formatVideosJson(items, res.data.items); // Format the recieved JSON object filled with videos
      callback(formatedVideos);
    }
  });
}
function getVideoStatistics(auth, youtube, items, count, callback) {

  // Convert the video ID:s of the provided videos to the appropriate format
  var IDs = "";
  if (Array.isArray(items)) {
    for (var i = 0; i < items.length; i++) {
      if (i != 0) {
        IDs += ", "
      }
      IDs += items[i].id.videoId;
    }
  }

  youtube.videos.list( // Call the Youtube API
  {
    auth: auth,
    part: "statistics",
    id: IDs,
    maxResults: count //integer 0-50, default 5
  },
  function(err, res) {
    if (err) {
      console.log("The API returned an error: " + err);
    } else {
      var formatedVideos = formatVideosJson(items, res.data.items); // Format the recieved JSON object filled with videos
      callback(formatedVideos);
    }
  });
}
function getVideoStatistics ( auth , youtube , items , count , callback ) { // Convert the video ID:s of the provided videos to the appropriate format var IDs = "" ; if ( Array . isArray ( items ) ) { for ( var i = 0 ; i < items . length ; i ++ ) { if ( i != 0 ) { IDs += ", " } IDs += items [ i ] . id . videoId ; } } youtube . videos . list ( // Call the Youtube API { auth : auth , part : "statistics" , id : IDs , maxResults : count //integer 0-50, default 5 } , function ( err , res ) { if ( err ) { console . log ( "The API returned an error: " + err ) ; } else { var formatedVideos = formatVideosJson ( items , res . data . items ) ; // Format the recieved JSON object filled with videos callback ( formatedVideos ) ; } } ) ; }
Get video statistics
Get video statistics