YouTubeAnalytics.Reports.query returns 403 Forbidden in Google Apps Script

耗尽温柔 提交于 2019-12-08 12:18:40

问题


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?


回答1:


You are right, Google Apps Script didn't request the required scopes. This has been fixed. If you re-run your script it should work.



来源:https://stackoverflow.com/questions/34726404/youtubeanalytics-reports-query-returns-403-forbidden-in-google-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!