我也有這個問題。你需要儘快登出的Gmail帳戶從Gmail權威性得到電子郵件ID:
<script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
<script>
function onSuccessG(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());
//now here write a code of login//
//
//now here write a code of login//
signOut();//call sign out function which will sign out user from their gmail accont
}
function onFailureG(error) {
console.log(error);
}
function renderButton() {
gapi.signin2.render('my-signin2', {
'scope': 'https://www.googleapis.com/auth/plus.login',
'width': 323,
'height': 35,
'longtitle': true,
'theme': 'dark',
'onsuccess': onSuccessG,
'onfailure': onFailureG
});
}
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function() {
console.log('User signed out.');
});
}
的可能重複[防止自動登錄時使用Google+登入(HTTP:/ /stackoverflow.com/questions/15484533/preventing-automatic-sign-in-when-using-google-sign-in) –