谷歌加登录:如何获取用户电子邮件


Google plus sign in : How to get the user email?

我在 examples 文件夹中的用户示例.php https://github.com/google/google-api-php-client 使用此代码在 Google plus 登录上进行一些测试。

一切都很顺利,除了一件事。连接后,我获得了这个网址:

http://MYURL/?code=4/vt_b0DsUU91UOYkB3ozIp-ZLITiL2irzaaUzyvtdph4.4gAL4kfDZGUVJvIeHux6iLafIxOglAI

我的问题是,我在哪里可以获得用户电子邮件?

谢谢

TL;DR:完全有效的解决方案:从Google OAuth 2.0 PHP API获取用户信息

您正在使用脱机流,此处详细介绍了该流:https://developers.google.com/accounts/docs/OAuth2WebServer#handlingtheresponse

此时,您获得了代码。

vt_b0DsUU91UOYkB3ozIp-ZLITiL2irzaaUzyvtdph4.4gAL4kfDZGUVJvIeHux6iLafIxOglAI

此代码需要交换为access_token。

使用 Google 图书馆交换访问令牌的代码:https://github.com/google/google-api-php-client/blob/master/examples/user-example.php#L66

使用access_token您可以发送 api 请求。