我正在使用google-api-php-client查询YouTube数据API。

首先,我从具有以下范围的用户那里获得 token :

[
    'https://www.googleapis.com/auth/userinfo.email',
    'https://www.googleapis.com/auth/userinfo.profile',
    'https://www.googleapis.com/auth/youtube.readonly',
    'https://www.googleapis.com/auth/yt-analytics-monetary.readonly',
    'https://www.googleapis.com/auth/yt-analytics.readonly',
    'https://www.googleapis.com/auth/youtubepartner',
    'https://www.googleapis.com/auth/youtubepartner-channel-audit',
]

然后我发出listChannels请求:
(new \Google_Service_YouTube($client))->channels->listChannels('snippet', [
    'mine'       => 'true',
    'maxResults' => 1,
]);

在大多数情况下,它就像一种魅力。我得到了他们的 channel 数据。

但有时它会抛出异常,代码为401和错误消息:
{
 "error": {
  "errors": [
   {
    "domain": "youtube.header",
    "reason": "youtubeSignupRequired",
    "message": "Unauthorized",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Unauthorized"
 }
}

对于具有多个 channel 的用户来说,情况似乎如此。但是我尝试在我的个人帐户中添加一个新 channel ,并在通过OAuth授权访问时选择该新 channel 。而且效果很好。

就其发生原因而言,这非常令人困惑,并且错误消息没有多大意义。由于它们的 token 绝对可以,因此我可以续签它们或查询其Google Plus个人资料,而不会出现问题。

有没有人遇到那个错误?

最佳答案

基于此documentationyoutubeSignupRequired表示用户具有未链接的Google Account,这意味着该用户具有Google帐户,但没有YouTube channel 。

以下是一些相关的帖子,可能会有所帮助:

  • Youtube API v3 return 401 when i try to upload video

  • Youtube v3 api 401 Unauthorized


  • 希望这可以帮助!

    关于php - YouTube数据API listChannels请求有时不会为具有多个 channel 的用户返回 channel 数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44848887/

    10-11 22:19
    查看更多