Google OAuth2 API v2 userinfo 始终为电子邮件返回 null



我正在尝试获取经过身份验证的用户的电子邮件地址。

我已经完成了使用作用域进行身份验证

email
profile
https://www.googleapis.com/auth/plus.login
https://www.googleapis.com/plus/v1/people/me
https://www.googleapis.com/auth/userinfo.email

此调用为电子邮件返回 null,但填充了名称、链接、图片等:

Userinfoplus userinfo2 = oauth2.userinfo().v2().me().get().execute();
log.info(userinfo2.toString());

输出:

{
"family_name" : "Homlish",
"gender" : "male",
"given_name" : "Paul",
"id" : "107004799409225320539",
"link" : "https://plus.google.com/107004799409225320539",
"locale" : "en",
"name" : "Paul Homlish",
"picture" : "https://lh4.googleusercontent.com/-bCRlXUqr__E/AAAAAAAAAAI/AAAAAAAABR8/LQCliyz_jgI/photo.jpg"
} 

检查我可以看到一个电子邮件字段,但它是空的。

知道我错过了什么吗?

尽管我使用的作用域不会提示用户输入额外的权限,但是否有任何不需要可以删除的作用域?

谢谢 保罗

通过将范围设置为"电子邮件",进行身份验证并使用com.google.api.client.googleapis.auth.oauth2.GoogleCredential和com.google.api.services.oauth2.Oauth2,我能够接收电子邮件:

GoogleCredential credential = new GoogleCredential().setAccessToken(tokenFromAuthentication); 
Oauth2 oauth2 = new Oauth2.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
.setApplicationName("Oauth2")
.build();
Userinfoplus userinfo = oauth2.userinfo().get().execute();

最新更新