我在我的web应用程序中使用google plus API。我可以把所有人从谷歌加中拉出来
我的代码是
$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');
这是我圈子里所有人的名单。但是我不知道别人的电子邮件地址和生日。我怎么也能拿到这些?
一旦你有了Google+ID的列表,你就需要调用people.get来获得这些用户的[公共]配置文件数据。在PHP中,这个调用看起来像$me = $plus->people->get('me');
。对于授权用户,可以使用"me"关键字。否则,您可以使用Google+ID拨打电话。
一旦你打了电话,你就可以提取出与你相关的属性(完整列表:https://developers.google.com/+/api/最新消息/人物)。
但是,要获得用户的Google电子邮件地址,除了plus.login
作用域之外,还需要包括https://www.googleapis.com/auth/userinfo.email
作用域。这意味着您只能获得授权用户的电子邮件地址。
请阅读Google+OAuth 2.0作用域上的文档,其中解释了您需要使用作用域https://www.googleapis.com/auth/userinfo.email
,然后将您的访问令牌发送到tokenInfo端点,以获取用户的电子邮件地址作为验证信息的一部分