YouTube 数据 API listChannels 请求有时不会 return 拥有多个频道的用户的频道数据
YouTube Data API listChannels request sometimes won't return channel data for users with multiple channels
我正在使用 google-api-php-client 查询 YouTube 数据 API。
首先,我从具有以下范围的用户处获得令牌:
[
'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,
]);
而且大多数时候它就像一个魅力。我得到他们的频道数据。
但有时会抛出异常,代码为401
,错误信息为:
{
"error": {
"errors": [
{
"domain": "youtube.header",
"reason": "youtubeSignupRequired",
"message": "Unauthorized",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Unauthorized"
}
}
它似乎发生在拥有多个频道的用户身上。但我尝试向我的个人帐户添加一个新频道,并在通过 OAuth 授权访问时选择该新频道。而且效果很好。
关于它发生的原因非常令人困惑,并且错误消息没有多大意义。因为他们的代币肯定没问题,我可以毫无问题地续订或查询他们的 Google Plus 配置文件。
有人遇到过那个错误吗?
基于此 documentation, youtubeSignupRequired
indicates that the user has an unlinked Google Account,这意味着用户有一个 Google 帐户但没有 YouTube 频道。
This error is commonly seen if you try to use the OAuth 2.0 Service Account flow. YouTube does not support Service Accounts, and if you attempt to authenticate using a Service Account, you will get this error.
The YouTube API blog post introducing Google Account support also discusses the youtubeSignupRequired error in more detail. Although the blog post explains the error for API version 2.1, the meaning of the error is still applicable.
以下是一些可能有帮助的相关帖子:
Youtube API v3 return 401 when i try to upload video
Service account doesnt work with youtube. Also please ensure that if you are using a gmail ID it must be linked to youtube otherwise you would get 401.
Youtube v3 api 401 Unauthorized
The reason "youtubeSignupRequired" usually means the YouTube account has not been set up properly or you have not created your YouTube channel yet. This is a requirement before you can upload videos. It would be great if Google could improve their error message for this case and make it a bit more verbose.
希望对您有所帮助!
我正在使用 google-api-php-client 查询 YouTube 数据 API。
首先,我从具有以下范围的用户处获得令牌:
[
'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,
]);
而且大多数时候它就像一个魅力。我得到他们的频道数据。
但有时会抛出异常,代码为401
,错误信息为:
{
"error": {
"errors": [
{
"domain": "youtube.header",
"reason": "youtubeSignupRequired",
"message": "Unauthorized",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Unauthorized"
}
}
它似乎发生在拥有多个频道的用户身上。但我尝试向我的个人帐户添加一个新频道,并在通过 OAuth 授权访问时选择该新频道。而且效果很好。
关于它发生的原因非常令人困惑,并且错误消息没有多大意义。因为他们的代币肯定没问题,我可以毫无问题地续订或查询他们的 Google Plus 配置文件。
有人遇到过那个错误吗?
基于此 documentation, youtubeSignupRequired
indicates that the user has an unlinked Google Account,这意味着用户有一个 Google 帐户但没有 YouTube 频道。
This error is commonly seen if you try to use the OAuth 2.0 Service Account flow. YouTube does not support Service Accounts, and if you attempt to authenticate using a Service Account, you will get this error.
The YouTube API blog post introducing Google Account support also discusses the youtubeSignupRequired error in more detail. Although the blog post explains the error for API version 2.1, the meaning of the error is still applicable.
以下是一些可能有帮助的相关帖子:
Youtube API v3 return 401 when i try to upload video
Service account doesnt work with youtube. Also please ensure that if you are using a gmail ID it must be linked to youtube otherwise you would get 401.
Youtube v3 api 401 Unauthorized
The reason "youtubeSignupRequired" usually means the YouTube account has not been set up properly or you have not created your YouTube channel yet. This is a requirement before you can upload videos. It would be great if Google could improve their error message for this case and make it a bit more verbose.
希望对您有所帮助!