Skip to content

Instantly share code, notes, and snippets.

@mhawksey mhawksey/main.js
Last active Oct 16, 2018

Embed
What would you like to do?
Using Google Apps Script to proxy YouTube Analytics Channel report data http://mashe.hawksey.info/?p=16234
// 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());
// 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
You can’t perform that action at this time.