YouTube Channel And Video Stats Using App Script

Following script read video stats of a youtube video

Get Youtube Video Stats
function getYouTubeVideoStats() {
  var sh=SpreadsheetApp.getActiveSheet();  
  
  var videoID=sh.getRange('B3').getValue();
  var data=YouTube.Videos.list('snippet, statistics, contentDetails', {id: videoID})    
  
  var item=data.items[0];    
    
  var title=item.snippet.title
  var commentCount=item.statistics.commentCount;
  var viewCount=item.statistics.viewCount;
  var likeCount=item.statistics.likeCount;
  var dislikeCount=item.statistics.dislikeCount;
  var duration=item.contentDetails.duration
  
  sh.getRange('B5').setValue(title);
  sh.getRange('B6').setValue(commentCount);
  sh.getRange('B7').setValue(viewCount);
  sh.getRange('B8').setValue(likeCount);
  sh.getRange('B9').setValue(dislikeCount);
  sh.getRange('B10').setValue(duration);
}

Get Youtube channel details

Get Youtube Channel Stats
function getYouTubeChannelStats() {
  var sh=SpreadsheetApp.getActiveSheet();  
  
  var videoID=sh.getRange('B3').getValue();
  var data=YouTube.Channels.list('snippet, statistics', {id: videoID})    
  
  var item=data.items[0];    
    
  var title=item.snippet.title;
  var videoCount=item.statistics.videoCount
  var subscriberCount=item.statistics.subscriberCount;
  var viewCount=item.statistics.viewCount;
  var s=item.statistics.hiddenSubscriberCount;
  
  
  sh.getRange('B5').setValue(title);
  sh.getRange('B6').setValue(videoCount);
  sh.getRange('B7').setValue(subscriberCount);
  sh.getRange('B8').setValue(viewCount);
  sh.getRange('B9').setValue(s);

}
Tags: No tags

Add a Comment

Your email address will not be published. Required fields are marked *