我在 PHP 中使用 Google 客户端库。
我已成功通过身份验证。
缺少一个简单的东西(我添加了正确的范围)。我如何检索
完成身份验证过程后用户的电子邮件。
以下是我所拥有的:
$client = new Google_Client();
$client->setClientId(MYCLIENTID);
$client->setClientSecret(MYSECRET);
$client->setRedirectUri(SOMEURLINMYSYSTEM);
$service = new Google_Service_Oauth2($client);
$client->addScope(Google_Service_Oauth2::USERINFO_EMAIL);
$client->authenticate($_GET['code']);//I have the right code, and I am being authenticated
//TODO Get from google the user's email ?????????
我在这里使用 PHP 库: https://code.google.com/p/google-api-php-client/wiki/OAuth2
最佳答案
糟糕,刚找到它:
$client = new Google_Client();
$client->setClientId(MYCLIENTID);
$client->setClientSecret(MYSECRET);
$client->setRedirectUri(SOMEURLINMYSYSTEM);
$service = new Google_Service_Oauth2($client);
$client->addScope(Google_Service_Oauth2::USERINFO_EMAIL);
$client->authenticate($_GET['code']);//I have the right code, and I am being authenticated
$client->authenticate($code);
$plus = new Google_Service_Plus($client);
$person = $plus->people->get('me');
var_dump($person);
关于php - 如何从 Google 检索用户的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23935913/