【问题标题】:How to get email address along with people list in google plus API如何在google plus API中获取电子邮件地址以及人员列表
【发布时间】:2013-07-16 09:24:28
【问题描述】:

我在我的网络应用程序中使用 google plus API。我可以从 google plus 中提取所有人

我的代码是

$this->client = new Google_Client();
        $this->client->setApplicationName($CI->config->item('application_name', 'googleplus'));
        $this->client->setClientId($CI->config->item('client_id', 'googleplus'));
        $this->client->setClientSecret($CI->config->item('client_secret', 'googleplus'));
        $this->client->setRedirectUri($CI->config->item('redirect_uri', 'googleplus'));
        $this->client->setDeveloperKey($CI->config->item('api_key', 'googleplus'));

        $this->plus = new Google_PlusService($this->client);
              $this->auth2 = new Google_Oauth2Service($this->client);

$peoples = $this->plus->people->listPeople('me','visible');

在这里,我正在获取我圈子中所有人的列表。但我不知道人们的电子邮件地址和生日。我怎样才能得到那些呢?

【问题讨论】:

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


    【解决方案1】:

    获得 Google+ ID 列表后,您需要调用 people.get 以获取这些用户的 [公开] 个人资料数据。在 PHP 中,这个调用看起来像 $me = $plus->people->get('me');。对于授权用户,可以使用“me”关键字。否则,您可以使用 Google+ ID 拨打电话。

    拨打电话后,您可以提取与您相关的属性(完整列表:https://developers.google.com/+/api/latest/people)。

    但是,要获取用户的 Google 电子邮件地址,除了 plus.login 范围之外,您还需要包括 https://www.googleapis.com/auth/userinfo.email 范围。这意味着您只能获取授权用户的电子邮件地址。

    【讨论】:

    • 您能详细说明您的尝试吗?除非我更了解你在做什么,否则我真的帮不了你。
    【解决方案2】:

    请阅读Google+ OAuth 2.0 scopes 上的文档,其中说明您需要使用范围https://www.googleapis.com/auth/userinfo.email,然后将访问令牌发送到 tokenInfo 端点以获取用户的电子邮件地址作为验证信息的一部分

    【讨论】:

    • 如何创建请求?
    猜你喜欢
    • 2020-09-04
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 2020-01-13
    • 2018-11-14
    • 1970-01-01
    • 2018-12-11
    相关资源
    最近更新 更多