我的代码中有一个错误。
我能够登录并检索用户信息。但是 signinCallback
又被调用了(我不知道怎么调用)。它显示我之前的用户信息不见了!
这是 HTML 端:
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="CLIENT_ID"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-scope="https://www.googleapis.com/auth/plus.profile.emails.read"
data-width="standard"
data-height="short">
</span>
</span>
这是 javascript 方面:
var AuthStates = {
google: null
};
function signinCallback(authResult) {
console.dir(authResult);
console.log('Sign-in state: ' + authResult['error']+authResult['access_token']);
AuthStates.google = authResult;
console.log('signinCallback');
chooseAuthProvider();
}
function chooseAuthProvider() {
if (AuthStates.google && AuthStates.facebook) {
if (AuthStates.google['access_token']) {
// Signed in with Google, you can now use Google+ APIs.
console.log(AuthStates.google);
gapi.client.load('plus','v1', function(){
var request = gapi.client.plus.people.get({
'userId': 'me'
});
request.execute(function(resp) {
document.getElementById('cname').value =resp.displayName;
document.getElementById('cemail').value =resp.emails[0].value;
console.log('Retrieved profile for:' + resp.displayName + ' ' + resp.emails[0].value);
});
});
}
}
它在第二个 signinCallback
Sign-in state: user_signed_outundefined
signinCallback
最佳答案
尝试更新的说明 “Integrating Google Sign-In into your web app” 页面。
关于javascript - Google+ signinCallback 调用了两次并且在处理过程中丢失了 authresult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24133161/