获得许可后,为什么我无法从Google Plus API检索用户电子邮件 [英] Why can't I retrieve the users email from Google Plus API after getting permission
本文介绍了获得许可后,为什么我无法从Google Plus API检索用户电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用google plus connect API,我可以向用户的电子邮件请求许可,但我似乎无权访问.
Using the google plus connect API I'm able to ask for permission for the users email but I don't seem to have access to it.
这是我正在使用的代码:
Here is the code I'm using:
require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_PlusService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Test Application");
$client->setClientId('XXXXX');
$client->setClientSecret('XXXXX');
$client->setRedirectUri('XXXXX');
$client->setDeveloperKey('XXXXX');
$client->setScopes(array('https://www.googleapis.com/auth/plus.login','https://www.googleapis.com/auth/userinfo.email'));
$plus = new Google_PlusService($client);
if (isset($_REQUEST['logout'])) {
unset($_SESSION['access_token']);
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['access_token'])) {
$client->setAccessToken($_SESSION['access_token']);
}
if ($client->getAccessToken()) {
$me = $plus->people->get('me');
print_r($me);
}
您知道用户授予权限后如何检索该电子邮件地址的想法吗?
Any idea how I retrieve the email address after the user has granted permission to get it?
推荐答案
有一个尚待解决的问题,因为您可以稍等片刻.
There's an open issue for that since a while that you can star.
同时,您可以改为使用针对OAuth2 Userinfo API的经过身份验证的请求.
In the meantime you can use an authenticated request against the OAuth2 Userinfo API instead.
require_once '../../src/contrib/Google_Oauth2Service.php';
(...)
$oauth2Service = new Google_Oauth2Service($client);
(...)
$userinfo = $oauth2Service->userinfo->get();
$email = $userinfo["email"];
这篇关于获得许可后,为什么我无法从Google Plus API检索用户电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文