我目前正在嘗試創建一個網站,用戶可以使用他的Google +帳戶登錄。大部分工作。我讓他們授予訪問我的網站。他們可以登錄並獲取他們的姓名和用戶ID,並在我的網站上顯示特定於他們的Google帳戶的內容。Google Auth2.0註銷
當有人想要登錄時,我嘗試登出網站,但Google登錄仍然記得剛剛登錄,登錄後立即運行代碼以再次登錄。如果我從谷歌刪除SSID cookie,它不會這樣做,所以我假設這是谷歌存儲我剛剛用x登錄的事實。
有沒有辦法讓我註銷時,谷歌不會立即用相同的帳戶登錄,而是要求谷歌用戶的電子郵件和密碼?
我覺得我錯過了一些明顯的東西,但我無法弄清楚如何處理這個問題。
<button class ="btn btn-primary" id="authorize-button" style="visibility: hidden">Log in</button>
<script>
var clientId = '';
var apiKey = '';
var scopes = '';
function handleClientLoad() {
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth,1);
}
function checkAuth() {
//alert("authorize");
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
}
function handleAuthResult(authResult) {
//alert("authorized");
//alert(authResult.access_token);
var authorizeButton = document.getElementById('authorize-button');
if (authResult && !authResult.error) {
authorizeButton.style.visibility = 'hidden';
makeApiCall();
} else {
authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
var token = document.createElement('h4');
token.appendChild(document.createTextNode(authResult.access_token));
document.getElementById('content').appendChild(token);
}
function handleAuthClick(event) {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
return false;
}
var x;
function makeApiCall() {
//return;
gapi.client.load('plus', 'v1', function() {
var request = gapi.client.plus.people.get({
'userId': 'me'
});
request.execute(function(resp) {
x = resp.id;
var heading2 = document.createElement('h4');
var heading3 = document.createElement('h4');
heading3.appendChild(document.createTextNode(resp.displayName));
heading2.appendChild(document.createTextNode(resp.id));
document.getElementById('content2').appendChild(heading2);
document.getElementById('content3').appendChild(heading3);
$.post("token.php", {id: x});
});
});
}
這是一個關鍵問題,我覺得Google絕對不支持這一點。 – 2015-02-05 10:50:56
Is gapi.auth.signOut();不是?我在Google頁面上看到它,同時尋找目標c等價物。 – 2015-02-11 15:49:37