gpt4 book ai didi

google-apps-script - Apps 脚本不断通过 Youtube 的 API 请求离线许可

转载 作者:行者123 更新时间:2023-12-03 05:29:09 25 4
gpt4 key购买 nike

我正在编写一个独立的 Google Apps 脚本,它将查询 Youtube Reports API 并返回对我的视频的分析。

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

当我用我的个人 gmail 帐户在一个新的脚本项目中尝试同样的事情时,一切正常。但是这样做有问题。当我通过自己的帐户查询 Youtube.Channels.list 时,我没有得到我拥有的任何其他 channel 的列表,只有我自己的个人 channel 。

我也试过 try it Youtube 文档中带有 Google+ 页面的功能,一切正常。

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

  • Youtube 数据 API
  • Youtube 分析 API
  • Google+ API(以防万一)

  • 我还尝试专门将 channel ID 设置为 channel==xxx 并删除变量 MyChannels 和 channel ,我仍然得到相同的结果。

    什么是可能的解决方案?

    这是我的代码示例:
    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'});
    }

    最佳答案

    Channel Reports documentation它说:

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



    如果 channel 所有者(即 channel 管理员)未运行您的 Apps 脚本,则会出现此问题。换句话说,如果您的 Apps 脚本是使用您的 Google 帐户编写的,该帐户也用作 YouTube channel 所有者,那么您很好,否则您会遇到身份验证问题。

    我记录的解决方案是 Using Google Apps Script to proxy YouTube Analytics Channel Reports这提供了更多细节。

    另一个可能导致问题的因素是您的 YouTubeAnalytics 查询丢失 start-dateend-date - Report: Query documentation将这些指示为必需参数。要解决此问题,您的函数可以重写为:
    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);
    }

    关于google-apps-script - Apps 脚本不断通过 Youtube 的 API 请求离线许可,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36485973/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com