javascript - Google Auth 用户电子邮件不存在

标签 javascript google-plus google-authentication

我正在为 Google Auth 2.0 使用 javascript api。我遇到了用户电子邮件未显示的问题,即使我使用 https://www.googleapis.com/auth/userinfo.email 请求.

我的代码是这样的:

gapi.auth.authorize({
                    client_id : 'xxxxxxxxxx.apps.googleusercontent.com',
                    scope : ['https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'],
                    immediate : false
                }, function(result) {

                    if (result != null) {
                        gapi.client.load('plus', 'v1', function() {
                            var request = gapi.client.plus.people.get({
                                'userId' : 'me'
                            });
                            request.execute(function(resp) {
                                console.log(resp);

                            });
                        });

                    }
                });

我缺少什么来获取用户的电子邮件?

最佳答案

虽然 userinfo.email Angular 色允许您访问信息,但 plus v1 客户端不提供。您将需要另外调用另一个端点以获取信息。

您将需要 oauth2 v2 端点,您可以使用 gapi.client.load('oauth2', 'v2', callback) 请求它。您需要的端点本身是 gapi.client.oauth2.userinfo.get()。这是未经测试的,但代码可能类似于:

  gapi.client.load('oath2','v2',function(){
    gapi.client.oauth2.userinfo.get().execute(function(resp){
      console.log(resp);
    });
  });

参见 How can I get the user's email address in google apps?Why can't I retrieve the users email from Google Plus API after getting permission对于一些相关问题和https://developers.google.com/accounts/docs/OAuth2从官方文档中获取更多详细信息。

关于javascript - Google Auth 用户电子邮件不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17748411/

相关文章:

ios - 获取 NSError 域 : "com.google.GTLJSONRPCErrorDomain" while fetching Google Calendar events in Swift

ios - 谷歌+登录SDK不工作

ios - 管理登录 IOS App 的用户

android - 检索到访问 token :null. com.google.android.gms.auth.GoogleAuthException:未知

javascript - 影响输入元素处理的 ID

javascript - 使用预制的 javascript 放大镜时如何水平排列图像并以 css 居中?

javascript - 围绕中心点绘制多边形

Javascript onclick将值插入数组

java - Google Domain API 不断返回 401/403 响应。我究竟做错了什么?

authentication - 重定向 URI 中 "postmessage"的用途是什么?