代码之家  ›  专栏  ›  技术社区  ›  Martin van Dam

使用服务帐户的YouTube报告API

  •  2
  • Martin van Dam  · 技术社区  · 6 年前

    根据Google的文档,您应该能够使用服务帐户使用YouTube报告API,而无需用户验证。

    目前,我有一个非常简单的示例,可以给我一个可用工作的列表,但可能是空的。但我的403权限被拒绝了。

    要求 :

    $client = new \Google_Client();
    $client->setAuthConfig('service-account-key.json');
    
    $client->addScope(Google_Service_YouTubeReporting::YT_ANALYTICS_MONETARY_READONLY);
    $client->addScope(Google_Service_YouTubeReporting::YT_ANALYTICS_READONLY);
    
    $youtube_reporting_service = new \Google_Service_YouTubeReporting($client);
    
    $jobs = $youtube_reporting_service->jobs->listJobs();
    

    回答 :

    Google\u Service\u异常

    {
        "error": {
            "code": 403,
            "message": "The caller does not have permission",
            "errors": [
                {
                    "message": "The caller does not have permission",
                    "domain": "global",
                    "reason": "forbidden"
                }
            ],
            "status": "PERMISSION_DENIED"
        }
    }
    

    我验证了已启用以下API:

    • YouTube报告API
    • YouTube数据API v3
    • YouTube分析API
    • Google+API (如果真有必要,我对此表示怀疑)

    我不明白的是,谷歌云平台上的项目与YouTube账户之间的关系应该如何。

    这跟 Delegating domain-wide authority to the service account ?

    然后是否需要启用G套件?

    我看到了一个类似的问题 How to grant access to Youtube Reporting API for a google service account? 存在,但自上次响应以来,该选项可能有点过时。我希望我的样本和补充将为这个问题带来新的曙光。

    有人有工作样品吗?可能使用其他语言。只要水流畅通。

    1 回复  |  直到 6 年前
        1
  •  1
  •   noogui    6 年前

    通常,服务帐户可用于模拟用户帐户。中提到了拨打授权电话 Preparing to make an authorized API call .

    但要回答这个问题, Service Accounts do not work with the YouTube API :

    服务帐户不适用于YouTube数据API调用,因为 服务帐户需要关联的YouTube频道,而您不能 将新渠道或现有渠道与服务帐户关联。如果您使用 服务帐户调用YouTube数据API,API服务器返回 错误类型设置为unauthorized且原因设置为的错误 youtubeSignupRequired。