【问题标题】:Retrieve google user info using php client library使用 php 客户端库检索 google 用户信息
【发布时间】:2014-07-21 04:56:13
【问题描述】:

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

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

所以这项工作正常,我检索了用户详细信息。但现在我需要使用 php.ini 检索记录的用户详细信息。我使用了 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 相同的凭据。请帮我。我做错了什么?

【问题讨论】:

  • 您的问题中似乎遗漏了一些信息。在第一种情况下,您如何进行身份验证?您使用的是 Google+ 登录按钮还是其他什么?

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 2020-05-08
    • 1970-01-01
    • 2012-06-02
    相关资源
    最近更新 更多