我正在移植一些现有的 js 代码,通过谷歌云平台进行身份验证(因为它们正在迁移到一组新的库)。
(迁移指南:https://developers.google.com/identity/oauth2/web/guides/migration-to-gis https://developers.google.com/identity/oauth2/web/guides/migration-to-gis)
我正在努力获取玩家的个人资料(以获取他们的电子邮件)。
旧的方法将遵循这一点(但正如它所说,它现在已被弃用 - 我一直在阅读新文档,但它主要围绕获得授权/身份验证,而不是后续内容):https://developers.google.com/identity/sign-in/web/people https://developers.google.com/identity/sign-in/web/people
e.g.
var profile = auth2.currentUser.get().getBasicProfile();
var email = profile.getEmail();
在我的新代码中,我通过新方法获得了访问令牌:
client_id: vm.clientId,
scope: SCOPE,
callback: (tokenResponse) => {
if (tokenResponse && tokenResponse.access_token) {
access_token = tokenResponse.access_token;
// HERE??? HOW DO I GET THE PROFILE?
}
}
})
(主要取自https://developers.google.com/identity/oauth2/web/guides/use-token-model https://developers.google.com/identity/oauth2/web/guides/use-token-model)
我在其他地方看到过这一点,但至少在我的情况下不起作用:
gapi.client.oauth2.userinfo.get().execute(function (resp) {
console.log(resp);
})
(如何从 Google 身份服务获取个人资料信息? https://stackoverflow.com/questions/72765524/how-to-get-profile-information-from-google-identity-services)
我已阅读迁移指南:“相反,请使用对新 JWT CredentialResponse 对象中凭证子字段的直接引用来处理用户配置文件数据。”但不知道如何获得此 Credentialresponse?
(https://developers.google.com/identity/gsi/web/guides/migration#token_response https://developers.google.com/identity/gsi/web/guides/migration#token_response)