-
-
Save linglung/962c6ae04401750613ca651a427372c8 to your computer and use it in GitHub Desktop.
Using Google Apps Script to proxy YouTube Analytics Channel report data http://mashe.hawksey.info/?p=16234
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
// instead of var results = YouTubeAnalytics.Reports.query(ids, start-date, end-date, metrics, optionalArgs); | |
var params = {"method" : "post", | |
"payload" : {'ids' : query.ids, | |
"startDate" : startDate, | |
"endDate": endDate, | |
"metrics": query.metrics, | |
"options": JSON.stringify(options) | |
} | |
}; | |
var yt_data = UrlFetchApp.fetch("https://script.google.com/macros/s/YOUR_APP_ID/exec", params); | |
var results = JSON.parse(yt_data.getContentText()); |
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
// to enable YouTubeAnalytics you need to go Resources > Advanced services and add YouTube Analytics (remembering to activate in Developer Console) | |
// Run > doPost to trigger authentication | |
// Publish > Deploy as web app | |
// - Execute as 'me' | |
// - Anyone, even anonymously | |
// Add you web app url to line 10 in main | |
function doPost(e) { | |
var results = YouTubeAnalytics.Reports.query(e.parameters.ids, e.parameters.startDate, e.parameters.endDate, e.parameters.metrics, JSON.parse(e.parameters.options)); | |
return ContentService.createTextOutput(JSON.stringify(results )) | |
.setMimeType(ContentService.MimeType.JSON); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment