简体   繁体   English

Google javascript client api:如何获取配置文件名称?

[英]Google javascript client api : how to fetch profile name?

I am trying to implement SignIn with Google with redirect approach.我正在尝试使用重定向方法使用 Google 实现登录。 I am following this link My code looks like below我正在关注链接我的代码如下所示

<script src="https://apis.google.com/js/platform.js?onload=startGoogleApp" async defer></script>
<script>

    var startGoogleApp = function () {
        gapi.load('auth2', function() {
            auth2 = gapi.auth2.init({
                client_id: '@googleClientId',
                ux_mode: 'redirect',
                redirect_uri: '@googleRedirectUri',
                fetch_basic_profile: true
            });

            auth2.signIn();
        });
    }
</script>

But issue is in Google's id_token is not having the name even though I have passed fetch_basic_profile: true I also tried with scope: 'profile' .但问题是谷歌的 id_token 没有名字,即使我已经通过了fetch_basic_profile: true我也尝试过scope: 'profile'

I want to fetch name along with email.我想获取姓名和电子邮件。 don't know what am I doing wrong here.不知道我在这里做错了什么。 I want it in part of token as it is mentioned in documentation I am following.我想要它作为令牌的一部分,因为它在我正在关注的文档中提到。 I don't want fetch name with additional api call.我不想通过额外的 api 调用来获取名称。 Is it possible?是否可以? id_token looks like this id_token 看起来像这样

{
  "iss": "accounts.google.com",
  "azp": "*********",
  "aud": "***********",
  "sub": "*********",
  "hd": "***.com",
  "email": "*****@***.com",
  "email_verified": true,
  "iat": 1599717107,
  "exp": 1599720707,
  "jti": "*******"
}

Googles Id token is not guaranteed to return all of the profile claims on ever response.不保证 Google 的 Id 令牌会在响应时返回所有个人资料声明。

If you want the users profile information then you should go though the Google People API.如果您想要用户的个人资料信息,那么您应该通过 Google People API。 people.get 人们.get

 // Make sure the client is loaded and sign-in is complete before calling this method.
  function execute() {
    return gapi.client.people.people.get({
      "resourceName": "people/me",
      "requestMask.includeField": "addresses",
      "sources": [
        "READ_SOURCE_TYPE_PROFILE"
      ]
    })
        .then(function(response) {
                // Handle the results here (response.result has the parsed body).
                console.log("Response", response);
              },
              function(err) { console.error("Execute error", err); });
  }
  gapi.load("client:auth2", function() {
    gapi.auth2.init({client_id: "YOUR_CLIENT_ID"});
  });

Code ripped from the try me found on people.get从在people.get 上找到的 try me 中撕下的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我们具有该用户的个人资料ID,则如何使用LinkedIn Javascript API获取其他用户的个人资料详细信息 - How to fetch profile details of another user using LinkedIn Javascript API, if we have profile id of that user 如何从使用 fetch api 和 javascript 获取的用户列表中的模型中显示用户配置文件 - How to show a user profile in a model from the list of users fetched using fetch api with javascript 如何通过Node Client从Google API获得真实姓名 - How to get real name from Google API via Node Client 如何使用google-api-javascript-client和Javascript访问Google Photos API并读取JSON数据? - How to Access Google Photos API with Javascript using google-api-javascript-client and read JSON data? 使用Google JavaScript Client Lib的Google Contacts API - Google Contacts API with Google JavaScript Client Lib 如何将AngularJS与Google API JavaScript客户端一起使用? - How do I use AngularJS with Google API JavaScript Client? 如何将Google API Javascript客户端库加载到Chrome应用中 - How to Load Google API Javascript Client Library into Chrome App 在 Google Calendar API 中获取用户个人资料名称和图像 - Getting user profile name and image in Google Calendar API 如何从Facebook javascript SDK获取个人资料图片? - How to fetch profile picture from facebook javascript SDK? Google Maps JavaScript中的api客户端json - Google maps api client side json in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM