从访问令牌获取Google个人资料信息

时间:2015-04-15 17:27:16

标签: php symfony google-api-php-client php-5.5

我有一个移动应用程序,它使用Google SDK对用户进行身份验证。该应用程序从Google检索访问令牌,然后通过此令牌向我的API发出请求。如何在我的API中使用此访问令牌获取用户的个人资料?

我正在尝试这个:

$client = new \Google_Client();
$client->setClientId('CLIENT_ID');
$client->setClientSecret('CLIENT_SECRET');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
// the following token I get through the mobile authentication
$token = array(
    'access_token' => 'ACCESS_TOKEN',
    'refresh_token' => 'REFRESH_TOKEN',
    'token_type' => 'TYPE',
    'expires_in' => 'EXPIRES',
    'id_token' => 'ID_TOKEN',
    'created' => 'CREATED_AT'
);
$client->setAccessToken(json_encode($token));
$plus = new \Google_Service_Plus($client);
$person = $plus->people->get('ID');

但我发现错误,我认为是因为Google开发者中的客户端配置("已安装的应用程序"),因为它是一款移动应用。

0 个答案:

没有答案