尝试获取我获得的用户 token :
Uncaught TypeError: profile.getAuthResponse is not a function
哪里
profile = googleUser
这是我的代码:
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
console.log('Token id: ' + profile.getAuthResponse().id_token);
}
那里没什么特别的。
我在 Google 文档中读到,出于安全目的,我应该使用函数 getAuthResponse().id_token 而不是 GoogleUser.getId()。
在这个问题中:Google access_token is undefined
这里Sharkos建议使用gapi.auth.getToken().access_token,但我得到null
有什么想法为什么我会收到这个错误吗?
最佳答案
试试这个
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
console.log('Token id: ' + googleUser.getAuthResponse().id_token);
}
您设置 var profile = googleUser.getBasicProfile();因此,您不能在 getBasicProfile() 上使用 getAuthResponse()。它必须是 googleUser.getAuthResponse()
关于javascript - Google 登录获取用户 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47037798/