Apps脚本不断要求使用Youtube API进行离线许可 [英] Apps Script keeps asking for offline permission with Youtube's API

查看:138
本文介绍了Apps脚本不断要求使用Youtube API进行离线许可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个独立的Google Apps脚本,用于查询Youtube Reports API并在我的视频中返回分析结果。



当我在Apps Script中进行身份验证时,我们用来管理各种Youtube频道的Google+页面,Apps脚本不断要求我授权脚本进行离线访问。



当我在一个新的脚本项目与我的个人Gmail帐户,一切工作正常。这样做有一个问题。当我通过我自己的帐户查询Youtube.Channels.list时,我没有收到我拥有的任何其他频道的列表,只是我自己的个人频道。



我也尝试过使用尝试功能带有Google+信息页的Youtube文档,并且工作正常。



对于这个脚本,我打开了以下高级服务:在Google Developer Console中启用:


  1. Youtube数据API

  2. Youtube Analytics API

  3. Google+ API(以防万一)

我也试过将channel id设置为channel = = xxx,并删除变量MyChannels和渠道,我仍然得到相同的结果。



有什么可能的解决方案?

以下是我的代码示例:

  function youTubeAnalytics(){
var myChannels = YouTube.Channels .list('id',{mine:true});
var channel = myChannels.items [0];
var channelId = channel.id;
var analyticsResponse = YouTubeAnalytics.Reports.query(
'channel =='+ channelId,
'estimatedMinutesWatched,views,likes,subscribersGained',
{dimensions:'video', 'max-results':'200',sort:'-views'});


解决方案

渠道报告文档它说:


授权请求的用户必须是频道的所有者


如果您的Apps脚本不是不是由频道所有者即渠道经理运营的。换句话说,如果您的Google Apps脚本是使用您的Google帐户编写的,而Google帐户也被用作YouTube频道所有者,那么您可能会遇到身份验证问题。



解决方案I已记录在使用Google Apps脚本代理YouTube Analytics频道报告,其中详细介绍了此信息。



另一个可能造成问题的因素是您的YouTubeAnalytics查询丢失开始日期结束日期 - Report:Query documentation 将这些参数指定为必需参数。要解决这个问题,你的函数可以改写为:

  function youTubeAnalytics(){
var myChannels = YouTube.Channels。列表('id',{mine:true});
var channel = myChannels.items [0];
var channelId = channel.id;
var analyticsResponse = YouTubeAnalytics.Reports.query(
'channel =='+ channelId,
'2010-01-01',
Utilities.formatDate(new Date(), 'GMT','yyyy-MM-dd'),
'estimatedMinutesWatched,views,likes,subscribersGained',
{dimensions:'video','max-results':'200',sort: '-views'});
Logger.log(analyticsResponse);
}


I'm writing a standalone Google Apps Script that will query the Youtube Reports API and return analytics on my videos.

When I authenticate in Apps Script with one of the Google+ pages that we use to manage our various Youtube Channels, Apps Script keeps asking me to authorize the script for offline access.

When I try the same thing in a new script project with my personal gmail account, everything works fine. There's a problem with doing it this way though. When I query the Youtube.Channels.list through my own account, I don't get a list of any of the other channels I own, just my own personal channel.

I've also tried this with the try it feature on the Youtube documentation with a Google+ page and things work fine.

For this script, I have the following advanced services turned on & enabled in the Google Developer Console:

  1. Youtube Data API
  2. Youtube Analytics API
  3. Google+ API (just in case)

I've also tried specifically setting the channel id to channel==xxx and removing the varibles MyChannels and channel and I still get the same results.

What could be a possible solution?

Here's an example of my code:

function youTubeAnalytics() {
     var myChannels = YouTube.Channels.list('id', {mine: true});
     var channel = myChannels.items[0];
     var channelId = channel.id;
     var analyticsResponse = YouTubeAnalytics.Reports.query(
     'channel==' + channelId,
     'estimatedMinutesWatched,views,likes,subscribersGained',
     {dimensions: 'video','max-results': '200',sort: '-views'});
     }

解决方案

In the Channel Reports documentation it says:

the user authorizing the request must be the owner of the channel

This issue surfaces if your Apps Script isn't been run by the channel owner ie a channel manager. In other words if your Apps Script is written using your Google account which is also used as the YouTube Channel owner you are fine, otherwise you hit authentication issues.

A solution I've documented is Using Google Apps Script to proxy YouTube Analytics Channel Reports which gives more detail about this.

Another factor that might be creating issues is your YouTubeAnalytics query is missing start-date and end-date - the Report: Query documentation indicates these as required parameters. To fix this your function could be rewritten as:

function youTubeAnalytics() {
  var myChannels = YouTube.Channels.list('id', {mine: true});
  var channel = myChannels.items[0];
  var channelId = channel.id;
  var analyticsResponse = YouTubeAnalytics.Reports.query(
  'channel==' + channelId, 
  '2010-01-01', 
  Utilities.formatDate(new Date(), 'GMT', 'yyyy-MM-dd'), 
  'estimatedMinutesWatched,views,likes,subscribersGained', 
  {dimensions: 'video','max-results': '200',sort: '-views'});
  Logger.log(analyticsResponse);
}

这篇关于Apps脚本不断要求使用Youtube API进行离线许可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆