Google OAuth API可以获取用户的电子邮件地址?

Google OAuth API可以获取用户的电子邮件地址?

问题描述:

我正在使用我自己的个人Google帐户与Google的OAuth 2.0游乐场玩耍,但我似乎无法使用操场恢复我的Gmail地址。

I am playing with Google's OAuth 2.0 Playground using my own personal Google account, but I cannot seem to recover my Gmail address using the playground.

我的范围使用的是:

email profile https://www.googleapis.com/auth/plus.login

但是当我打电话给API时:

But when I call the API:

https://www.googleapis.com/oauth2/v2/userinfo

我得到关于用户的各种信息,如姓氏,名字,性别,图片等,但不会返回用户的电子邮件。

I get various information about the user such as family name, first name, gender, picture, etc. but it does not return the user's email.

如何检索用户的电子邮件地址?我有错误的范围,还是调用错误的API?我觉得这应该很简单,但是我一直在努力解决这个问题,几个小时,我找不到一贯提供用户电子邮件地址的API和范围组合。

How do I retrieve the user's email address? Do I have the wrong scope or am I calling the wrong API? I feel like this should be very simple but I have literally been trying to figure this out for hours and I cannot find an API and scope combination that consistently provides the user's email address.

这里有很多问题,您正在做什么以及如何尝试。

There are a lot of issues here in what you're doing and how you're trying to do it.

首先, https://www.googleapis.com/oauth2/v2/userinfo 终结点已被弃用,并计划于2014年9月移除。它已开始不一致的工作 - 所以不要使用它。

For starters, the https://www.googleapis.com/oauth2/v2/userinfo endpoint is deprecated, and scheduled to be removed in September 2014. It has begun working inconsistently - so don't use it.

正如@abraham所说,你将使用 people.get 端点 https://www.googleapis.com/plus/v1/people/me 。这应该为您提供包含地址数组的电子邮件字段。在你的情况下,可能只有一种类型的帐户。

As @abraham noted, you'll use the people.get endpoint at https://www.googleapis.com/plus/v1/people/me. This should give you the emails field containing an array of addresses. In your case, there will likely be only one that has a type of "account".