Created
May 15, 2020 08:22
-
-
Save abonzer/b40f290664f85b586e362af3c2243aea to your computer and use it in GitHub Desktop.
Quickstart - YouTube Data API with Google App Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Apps Script Code Samples :- https://developers.google.com/youtube/v3/code_samples/apps-script | |
// Google Apps Script Quickstart ( with YT Data API) :- https://developers.google.com/youtube/v3/quickstart/apps-script | |
// YouTube Analytics API (AppScript) :- https://developers.google.com/apps-script/advanced/youtube-analytics | |
// YouTube - Data API > Video :- https://developers.google.com/youtube/v3/docs/videos | |
var ss = SpreadsheetApp.openById('1cNyTGnETUXXXXXXXXXXhq88zHeW4k7EoD7RzlS-8UM'); | |
var YTTracker = ss.getSheetByName('YTTracker'); | |
var Growth = ss.getSheetByName('Growth'); | |
function getYTChannelInfo() { | |
// 1. get Basic info Of Youtube channel ( id, title, viewCount, videoCount, subscriberCount etc. ) | |
// --------------------------------------------------------------------------------------------- | |
var YouTubeChannelID = 'UCapQ8VzljfmUW5OM-ynsyCQ'; | |
var response = YouTube.Channels.list('snippet,contentDetails,statistics', { | |
'id': YouTubeChannelID | |
}); | |
var channel = response.items[0]; | |
// channel.id | |
// channel.snippet.title | |
// channel.statistics.viewCount | |
// channel.statistics.subscriberCount | |
// channel.statistics.videoCount | |
// 2. Get List oF YouTube Channel Videos | |
// --------------------------------------- | |
var results = YouTube.Search.list('id,snippet', { | |
channelId: YouTubeChannelID, | |
maxResults: channel.statistics.videoCount + 2 | |
}); | |
// append list into Sheet (access video Data) | |
for (var i = 0; i < results.items.length; i++) { | |
var vid = results.items[i]; | |
if(vid.id.kind !== 'youtube#channel'){ | |
var vidID = vid.id.videoId; | |
var vidData = vid.snippet; | |
// Snippet > description, title, liveBroadcastContent, publishTime, publishedAt, channelId, channelTitle, thumbnails( high, default, medium |>| heigh, twidth, url ) | |
var dataRow = [vidID, vidData.title ]; | |
ss.getSheetByName('YTvideoList').appendRow(dataRow); | |
} | |
} | |
var dataRow = [channel.id, channel.snippet.title, channel.statistics.viewCount, channel.statistics.hiddenSubscriberCount, channel.statistics.subscriberCount, channel.statistics.videoCount, channel.statistics.commentCount]; | |
YTTracker.appendRow(dataRow); | |
} | |
function getVideoInfo(){ | |
var vidID = 'crqUDl8BPWI'; | |
var data = YouTube.Videos.list('snippet','statistics',{id: vidID}); | |
var item = data.items[0]; // https://developers.google.com/youtube/v3/docs/videos | |
return [item.statistics.viewCount,item.statistics.likeCount, item.statistics.dislikeCount, item.statistics.commentCount] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment