machinepack-youtubenodemachines/youtubeAPICalls.js
function getChannelUsername(auth, youtube, username, callback) {
  youtube.channels.list( // Call the Youtube API
    {
      auth: auth,
      part: "snippet, statistics",
      order: "date",
      forUsername: username,
      maxResults: 1 // Integer 0-50, default 5
    },
    function(err, res) {
      if (err) {
        console.log("The API returned an error: " + err);
      } else {
        if (res.data.items[0] !== undefined) { // Check if a result was found
          var formatedChannel = formatChannelJson(res.data.items[0]) // Format the recieved JSON object
          callback(formatedChannel);
        } else {
          callback([]);
        }
      }
    }
  );
}
function getChannelUsername(auth, youtube, username, callback) {
  youtube.channels.list( // Call the Youtube API
    {
      auth: auth,
      part: "snippet, statistics",
      order: "date",
      forUsername: username,
      maxResults: 1 // Integer 0-50, default 5
    },
    function(err, res) {
      if (err) {
        console.log("The API returned an error: " + err);
      } else {
        if (res.data.items[0] !== undefined) { // Check if a result was found
          var formatedChannel = formatChannelJson(res.data.items[0]) // Format the recieved JSON object
          callback(formatedChannel);
        } else {
          callback([]);
        }
      }
    }
  );
}
function getChannelUsername ( auth , youtube , username , callback ) { youtube . channels . list ( // Call the Youtube API { auth : auth , part : "snippet, statistics" , order : "date" , forUsername : username , maxResults : 1 // Integer 0-50, default 5 } , function ( err , res ) { if ( err ) { console . log ( "The API returned an error: " + err ) ; } else { if ( res . data . items [ 0 ] !== undefined ) { // Check if a result was found var formatedChannel = formatChannelJson ( res . data . items [ 0 ] ) // Format the recieved JSON object callback ( formatedChannel ) ; } else { callback ( [ ] ) ; } } } ) ; }
Get a Youtube channel via channel name
Get a Youtube channel via channel name