3

我在我的网络应用程序中使用 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');

在这里,我得到了我圈子里所有人的名单。但我不知道人们的电子邮件地址和生日。我怎样才能得到那些呢?

4

2 回答 2

3

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

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

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

于 2013-07-17T20:14:46.773 回答
0

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

于 2013-07-16T19:01:26.807 回答