问题描述
按照 Google 的文档,您应该能够通过使用服务帐户在无需用户身份验证的情况下使用 YouTube Reporting 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 = 新 Google_Service_YouTubeReporting($client);$jobs = $youtube_reporting_service->jobs->listJobs();
回应:
Google_Service_Exception
<代码>{错误": {代码":403,"message": "调用者没有权限",错误":[{"message": "调用者没有权限",域":全球",原因":禁止"}],状态":PERMISSION_DENIED"}}
我验证了以下 API 已启用:
- YouTube 报告 API
- YouTube 数据 API v3
- YouTube 分析 API
- Google+ API (如果真的有必要,我对此表示怀疑)
我不明白的是 Google Cloud Platform 中的项目与 YouTube 帐户之间的关系应该如何.
这与 全域委派有关服务帐户的权限?
您是否需要启用 G Suite?
我看到一个类似的问题 如何为 google 服务帐户授予对 Youtube Reporting API 的访问权限? 存在,但自上次响应以来可能有点老了.我希望我的示例和补充内容能为这个问题带来新的启发.
有人有工作样本吗?可能是其他语言.只要流程畅通.
一般来说,服务帐户可用于模拟用户帐户.准备进行授权 API 调用中提到了进行授权调用..p>
但要回答这个问题,服务帐户不适用于 YouTube API:
<块引用>服务帐户不适用于 YouTube 数据 API 调用,因为服务帐户需要关联的 YouTube 频道,而您不能将新的或现有的频道与服务帐户相关联.如果你使用一个服务帐户调用 YouTube 数据 API,API 服务器返回错误类型设置为未授权且原因设置为的错误youtubeSignupRequired.
Following Google's documentation you should be able to use the YouTube Reporting API without user authentication by using a Service Account.
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
{
"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"
}
}
I verified that the following APIs were enabled:
- YouTube Reporting API
- YouTube Data API v3
- YouTube Analytics API
- Google+ API (Having my doubts on this one if that is really necessary)
The thing I don't understand is how the relation should be between projects in Google Cloud Platform and the YouTube accounts.
Has this to do with Delegating domain-wide authority to the service account?
Are you then required to have G Suite enabled?
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.
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.
But to answer the question, Service Accounts do not work with the YouTube API:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!