我正在尝试通过 google plus api 获取 Youtube 用户名。我使用来自 Plus ang YT api 的 php 服务,我正在使用 symfony 2。获取访问令牌工作正常,我不打算把它放在这里。google plus服务也没有问题,授权后我得到了我需要的所有信息。在 YT 的情况下,我收到错误:不足的权限错误所以我在这里检查我的访问令牌范围: https ://www.googleapis.com/oauth2/v1/tokeninfo?access_token=ACCESS_TOKEN 并且我的访问令牌的范围仅适用于Google Plus,我无法强制 google Api php clinet 也使 YT 范围可用。有任何想法吗?
这是我的代码:
require_once '../src/google_api_php_client/src/Google_Client.php';
require_once '../src/google_api_php_client/src/contrib/Google_PlusService.php';
require_once '../src/google_api_php_client/src/contrib/Google_YouTubeService.php';
$client = new Google_Client();
$client->setScopes('https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/plus');
$youtube = new Google_YouTubeService($client);
if(!empty($allR['code'])){
$client->setClientId('clientIDxxx');
$client->setClientSecret('SecretXXX');
$client->setRedirectUri('postmessage');
$client->authenticate($allR['code']);
$token = json_decode($client->getAccessToken());
}