【问题标题】:Obtain youtube username from google Plus api - access token scope insufficientPermissions从 google Plus api 获取 youtube 用户名 - 访问令牌范围不足权限
【发布时间】:2013-08-14 23:29:44
【问题描述】:

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

【问题讨论】:

    标签: youtube-api google-api google-api-php-client


    【解决方案1】:

    首先,确保您在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);
    

    【讨论】:

      猜你喜欢
      • 2015-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-22
      • 2014-07-08
      • 2015-02-11
      • 2012-06-12
      • 1970-01-01
      相关资源
      最近更新 更多