I have used the same script to pull the View metric for specific videos and put it into a spreadsheet for more than a year successfully. Now, all of a sudden the script throws me a forbidden error on the YouTubeAnalytics.Reports.query line.
I created a blank Apps Script project with the following code to test the issue:
function myFunction() {
var report = YouTubeAnalytics.Reports.query('channel==MY_CHANNEL_ID','2015-01-01','2015-12-31','views', {filters: 'video==MY_VIDEO_ID'});
Logger.log(report);
}
It throws the same error.
The Advanced Google services are switched on and also enabled in the Developers Console.
The strange thing is that when I try the same query in the Developers Console API Explorer, it works fine.
So to me it seems like Google Apps Script can not identify properly the required scopes to run the script. In fact, I only have the youtube.readonly scope in the test project, while the API Explorer also asked for youtube, yt-analytics-monetry.readonly,yt-analytics.readonly.
Test project identified scopes
Any suggestions?