In Google Apps Script, access to YouTube Reporting API is Forbidden

最后都变了- 提交于 2019-12-05 09:24:25

问题


I have used YouTube Reporting API in Google Apps Script. Despite the no code changes, Forbidden is now thrown January 12th.

In reference to Google's document, I wrote the following code.

var myChannels = YouTube.Channels.list('id', {mine: true});
var channel = myChannels.items[0];

var today = new Date();
var todayFormatted = Utilities.formatDate(today, 'JST', 'yyyy-MM-dd');

var videoId = "MY_VIDEO_ID";

try {
  var results = YouTubeAnalytics.Reports.query(
    'channel==' + channel.id,
    todayFormatted,
    todayFormatted,
    'views',
  {
    dimensions: 'day',
    sort: '-day',
    filters:'video==' + videoId
  });
} catch (e) {
  Logger.log(e)  //Exception: Forbidden
}

OAuth authentication, YouTube Analytics API has been enabled in the Google Developer Console and Advanced Google Services.

I think there is a problem with my account, but is going the same problem in other accounts. Strangely, it will work normally in APIs Explorer.

Perhaps, this is the same problem as the post below.

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

Cause, I believe because does not contain the "yt-analytics.readonly" to OAUTH2 SCOPES.

In fact, it had been included yt-analytics.readonly to APIs Explorer in OAUTH2 SCOPES. So, it could successfully run. Perhaps, even before January 12. However, in spite of using youtube analytics api in this script, it does not contain a yt-analytics.readonly.

Why such a problem is happening?

来源:https://stackoverflow.com/questions/34949334/in-google-apps-script-access-to-youtube-reporting-api-is-forbidden

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