php - 如何从 Google 检索用户的电子邮件

标签 php oauth google-api google-oauth

我在 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/

相关文章:

c# - 在 C# 中解密用 PHP 加密的字符串 (Blowfish)

javascript - 如何使用我的 Chrome 扩展文件分发 OAuth2 客户端 ID?

php - 如何在 Laravel Mix 中安装 Font Awesome

PHP 预替换 : "a period with numbers on each side"

python - 推特 API : simple status update (Python)

c# - owin oauth 发送附加参数

java - 谷歌日历 Activity , session 详情未设置

android - 使用所需的时区从毫秒显示正确的时间

ios - 添加、更新有效,但如何使用 iOS Google Sheets API v4 进行追加?

c# - 如何在不到 6 小时的执行时间内测试 500 万亿个组合