Javascript Google登录获取用户令牌
尝试获取我获得的用户令牌: 未捕获的TypeError:profile.getAuthResponse不是函数 在哪里 profile=googleUser 这是我的代码:Javascript Google登录获取用户令牌,javascript,google-signin,Javascript,Google Signin,尝试获取我获得的用户令牌: 未捕获的TypeError:profile.getAuthResponse不是函数 在哪里 profile=googleUser 这是我的代码: function onSignIn(googleUser) { var profile = googleUser.getBasicProfile(); console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an I
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()
在这个问题上:在这里,Sharkos建议使用gapi.auth.getToken().access_令牌,但我得到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()
可能存在的副本