YouTube报告API使用服务帐户 [英] YouTube Reporting API using Service Account

查看:481
本文介绍了YouTube报告API使用服务帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循Google的文档,您应该可以在不使用用户身份验证的情况下使用YouTube报告API。

Following Google's documentation you should be able to use the YouTube Reporting API without user authentication by using a Service Account.

目前我有一个非常简单的示例,应该给出我列出了可用的工作,但可能是空的。但是我得到了一个拒绝的403权限。

Currently I have a very simple sample that should give me a list of available Jobs, could be empty though. But I get a 403 permission denied.

请求

Request:

$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();

响应

Response:

Google_Service_Exception

Google_Service_Exception

{
    "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已启用:

I verified that the following APIs were enabled:


  • YouTube报告API

  • YouTube数据API v3

  • YouTube Analytics API

  • Google+ API (如果真的有必要的话,请对此表示怀疑)

  • YouTube Reporting API
  • YouTube Data API v3
  • YouTube Analytics API
  • Google+ API (Having my doubts on this one if that is really necessary)

我不明白的是Google Cloud Platform中的项目与YouTube帐户之间的关系应如何。

The thing I don't understand is how the relation should be between projects in Google Cloud Platform and the YouTube accounts.

这是否与将全域权限授予服务帐户

您是否需要启用G Suite?

Are you then required to have G Suite enabled?

我看到类似的问题如何授予对Youtube Reporting API访问Google服务帐户的权限?
存在,但自上次回复以来可能会有点老旧。我希望我的样本和新增内容能够为这个问题提供一个新的亮点。

I see a similar question How to grant access to Youtube Reporting API for a google service account? exists, but that one may be a bit aged since the last response. I hope my samples and additions will shine a new light over this question.

有人有工作样本吗?可能是其他语言。只要流程清晰即可。

Is there someone with a working sample? May be in other languages. As long as the flow is clear.

推荐答案

通常,服务帐户可以用来模拟用户帐户。在准备进行授权API调用中提到了进行授权调用。

In general, service accounts can be used to impersonate a user account. Making authorized calls is mentioned in Preparing to make an authorized API call.

但要回答这个问题,服务帐户不适用于YouTube API

But to answer the question, Service Accounts do not work with the YouTube API:


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

Service accounts do not work for YouTube Data API calls because service accounts require an associated YouTube channel, and you cannot associate new or existing channels with service accounts. If you use a service account to call the YouTube Data API, the API server returns an error with the error type set to unauthorized and the reason set to youtubeSignupRequired.

这篇关于YouTube报告API使用服务帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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