Php HTTPS获取请求到https://www.googleapis.com/plus/v1/people/me

Php HTTPS获取请求到https://www.googleapis.com/plus/v1/people/me,php,Php,好的,这是我的一段代码 $client = new Google_Client(); $client->setScopes(array('https://www.googleapis.com/auth/plus.me','https://www.googleapis.com/auth/userinfo.email')); $plus = new Google_PlusService($client); if (isset($_SESSION['token'])) { $client-

好的,这是我的一段代码

$client = new Google_Client();
$client->setScopes(array('https://www.googleapis.com/auth/plus.me','https://www.googleapis.com/auth/userinfo.email'));
$plus = new Google_PlusService($client);

if (isset($_SESSION['token'])) {
  $client->setAccessToken($_SESSION['token']);
} else {
    $_SESSION['auth_token'] = $client->authenticate();
}
现在我有了$u会话['auth_token'],它包含如下内容

{"access_token":"ya29.AHESblablablabalbalbalbagTUI4-MfZvwtb6A","token_type":"Bearer","expires_in":3600,"id_token":"blablablabalbalbalba.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiY2lkIjoiNzAzNTg5ODA3MjMxLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiYXpwIjoiNzAzNTg5ODA3MjMxLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiYXVkIjoiNzAzNTgblablablabalbalbalbaRlbnQuY29tIiwiaGQiOiJnZW9mbGV4LmNvbS5teSIsInZlcmlmaWVkX2VtYWlsIjoidHJ1ZSIsImVtYWlsX3blablablabalbalbalbaFzei00N25nN3VoLU5NUmh3IiwiYXRfaGFzaCI6IllEeC13UXN6LTQ3bmc3dWgtTk1SaHciLCJpYXQiOjEzNzQ1NjA1NDcsImV4cCI6MTM3NDU2NDQ0N30.ek1FX-pY8BdaI8sDhA0rwmiIDyBV6pHPvBi-l7BxDJCR-YoDQGFN8y-kA1xg-vmoReiVCwhvQhHK__jc-xFSLfJDLbwk-UGyRKu_O7ZCaSviP7WupexIYvLGCyvgLBdjG3K7UIcq0o3L15mQPvQJr9LA7325gwEOZ12Pc1lAHKw","refresh_token":"1\/Y7oilVvUUutfkKMDfblablablabalbalbalbaE","created":1374560847}
我的问题是,如何获取用户的电子邮件?我知道你可以打电话

https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=youraccess_token
但这是获取用户电子邮件的“官方”方式吗?因为这里写着

您的应用程序在使用Google进行身份验证时收到的访问令牌可用于获取有关用户的其他配置文件信息。请注意,谷歌正在修改不同端点的行为以简化其使用。根据现有的行为,我们目前建议如下。如果您使用Google+登录,则应始终通过使用访问令牌向发送HTTPS GET请求以验证请求,从People API检索用户配置文件信息


所以我想最好的方法是执行HTTPS GET请求到googleapis.com。。但我不知道怎么做。有人能带头吗?

创建一个Google_Oauth2Service对象(将其置于$plus初始化下),如:

成功验证客户端使用后:

$userInfo = $oauth2->userinfo->get();
$email = $userInfo['email'];

我这样做了,但在此之前,我需要添加require_once“googleapi php client/src/contrib/google_Oauth2Service.php”;正确的?但在此之后,我得到了这个错误“致命错误:类”Google_TokeninfoServiceResource“未找到”。事实上,当我试图在google api php client/examples/userinfo/中运行index.php示例时,它返回了相同的错误OK得到了它。你的回答是正确的。该错误是由于最新的google api php客户端文件(版本0.6.3)引起的。必须降级到0.6.2版本才能正常工作。thanksHow关于创建圈或向圈中添加人?它必须使用
Google\u Service\u PlusDomains
class而不是
Google\u Service\u Oauth2
class?我在使用
Google\u Service\u PlusDomains
时也遇到了这个错误,比如:
$this->Google=new\Google\u Service\u PlusDomains($this->client)$这->谷歌->人->获取('me'
$userInfo = $oauth2->userinfo->get();
$email = $userInfo['email'];