[英]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.