我正在移植一些现有的js代码,用于与Google Cloud平台进行身份验证(因为他们正在迁移到一组新的库)。
(迁移指南:https://developers.google.com/identity/oauth2/web/guides/migration-to-gis)
我正在努力获取玩家的个人资料(以获取他们的电子邮件)。
旧方法可能是这样的(但正如它所说,现在已经过时了 - 我一直在阅读新文档,但大多数都是关于获取授权/身份验证,而不是其后续步骤): https://developers.google.com/identity/sign-in/web/people
例如:
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)
我在其他地方看到过这个提到,但至少在我的情况下它不起作用:
gapi.client.oauth2.userinfo.get().execute(function (resp) {
console.log(resp);
})
我已经通过迁移指南阅读到:“相反,使用新的JWT CredentialResponse对象中凭据子字段的直接引用来处理用户配置文件数据。”但是不知道如何获取此Credentialresponse? (https://developers.google.com/identity/gsi/web/guides/migration#token_response)