使用php客户端库检索谷歌用户信息

时间:2014-07-21 04:56:13

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

实际上我使用javascript客户端来检索用户个人资料信息。所以我使用了以下api调用

gapi.client.load('plus', 'v1', function() {
 var request = gapi.client.plus.people.get({
   'userId': 'me'
 });
 request.execute(function(resp) {     
 });
});

所以这项工作正常,我检索了用户详细信息。但现在我需要使用php检索记录的用户详细信息。我使用google-php-client-lib这是我的代码

    $client = new Google_Client();
    $client->setClientId('xxx');
    $client->setClientSecret('xxx');
    $client->setDeveloperKey('xxx');
    $client->setRedirectUri('http://localhost');
    $client->setScopes(array('https://www.googleapis.com/auth/plus.me'));

    try{
        $plus = new Google_Service_Plus($client);
        return $person = $plus->people->get('me');
    } catch (Google_Service_Exception $e){
        error_log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'.$e->getMessage());
    }

但这会返回以下异常

  

调用GET https://www.googleapis.com/plus/v1/people/me?key=xxx时出错:(401)凭据无效。实际上我使用了相同的凭据,我曾经使用过javascript。请帮我。我做错了什么?

1 个答案:

答案 0 :(得分:0)

在我的代码中,我只是将clientId和clientSecret传递给Google_Client,而不是developerKey。 也许这就是问题?

即使在他们的官方示例中,他们也不使用开发者密钥,请参阅FileUploadExample

相关问题