0

我正在尝试通过 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()); 
}
4

1 回答 1

0

首先,确保您在devconsole中启用了 YouTube Data API v3 。

然后尝试从devconsole设置客户端 ID 和密码,而不是设置范围。

$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'],
    FILTER_SANITIZE_URL);
$client->setRedirectUri($redirect);

// YouTube object used to make all Data API requests.
$youtube = new Google_YoutubeService($client);

$plus = new $youtube = new Google_PlusService($client);
于 2013-08-13T14:05:36.637 回答