Skip to content

Instantly share code, notes, and snippets.

@mhawksey mhawksey/main.js
Last active Mar 9, 2020

What would you like to do?
Using Google Apps Script to proxy YouTube Analytics Channel report data
// 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("", 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 ))
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.