【发布时间】:2015-08-23 06:13:43
【问题描述】:
我的任务是导入上传到 YouTube 上的视频的视频详细信息。
我有一个帐户,即视频所有者。我在控制台中有设置凭据:https://console.developers.google.com/project/XXXXX/apiui/credential。我在那里创建了 OAuth 服务帐户。
稍后在脚本中我使用文档中的代码(API 的 v3 版本):
$credentials = new Google_Auth_AssertionCredentials(
$clientEmail,
[
'https://www.googleapis.com/auth/youtube',
'https://www.googleapis.com/auth/youtube.force-ssl',
'https://www.googleapis.com/auth/youtube.readonly',
'https://www.googleapis.com/auth/youtubepartner',
],
$privateKeyContents
);
$this->client->setAssertionCredentials($credentials);
/** @var Google_Auth_OAuth2 $auth */
$auth = $this->client->getAuth();
if ($auth->isAccessTokenExpired()) {
$auth->refreshTokenWithAssertion();
}
身份验证工作正常。我已将记录器附加到 Google 客户端,我可以看到每个请求都传递了 Authorization: Bearer XXXXXXX 标头。
但问题在于,YouTube 似乎并未将此身份验证视为对实际资源所有者的身份验证。例如,如果我请求 Video Snippet,它会返回不带标签(出于某种原因标签只能由所有者看到)。
如果我从这里https://developers.google.com/youtube/v3/docs/videos/list?hl=ru 提出相同的请求,它会完美运行。
可能是什么问题?
日志中的请求如下所示:
[2015-06-08 14:50:02] name.DEBUG: OAuth2 authentication [] []
[2015-06-08 14:50:02] name.DEBUG: cURL request {"url":"https://www.googleapis.com/youtube/v3/playlists?part=id%2Csnippet&channelId=XXXXXXXXXXXX&maxResults=50","method":"GET","headers":{"authorization":"Bearer ya29.XXXXX-XXXXXX","accept-encoding":"gzip"},"body":null} []
这与我在跟踪 Google Javascript 客户端在文档页面上发出的请求时看到的不同。域不同,Javascript客户端传递更多的headers等。
如何使它与 PHP 一起工作?
【问题讨论】:
标签: php google-api youtube-api youtube-data-api google-api-php-client