我正在我的应用程序中集成谷歌登录。我需要存储电子邮件、姓名、年龄范围、位置。因此,在登录时,我将范围设置为个人资料、电子邮件和 profile.auth.agerange.read。
gapi.signin2.render('g-signin2', {
'scope': 'email profile https://www.googleapis.com/auth/userinfo.profile openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/profile.agerange.read',
'width': 240,
'height': 50,
'longtitle': true,
'theme': 'dark',
'onsuccess': onSuccess,
'onfailure': onFailure
});
但是当我使用 GoogleIdTokenVerifier 验证生成的 id_token 时,我仍然看不到有效负载中的年龄或位置字段。
任何人都可以建议如何获取这些详细信息。
最佳答案
很可能不会向位置和年龄组提供基本负载。 并且您需要调用额外的 API:
- GET v1/people/me?personFields=ageRanges与 https://www.googleapis.com/auth/userinfo.profile范围;
- GET v1/people/me?personFields=birthdays与 https://www.googleapis.com/auth/user.birthday.read范围。
此外,请查看 get-user-info-via-google-api主题。
关于java - 如何在进行谷歌登录时获取用户的年龄和位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56779221/