1
我跟着tutorial by google但我有問題。回調函數永遠不會被調用。 的代碼在本地主機 跑到這是我的代碼:谷歌登錄服務器端
<!DOCTYPE html>
<html lang="en">
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://apis.google.com/js/client:platform.js?onload=start" async defer></script>
<script>
function start() {
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: '<my-client-id>',
scopes: ['https://www.googleapis.com/auth/calendar']
});
});
}
function signInCallback(authResult) {
document.write("here");
if (authResult['code']) {
document.write("code is good");
} else {
document.write("error");
}
}
</script>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="signinButton">Sign in with Google</button>
<div id="result"></div>
<script>
$('#signinButton').click(function() {
auth2.grantOfflineAccess({'redirect_uri': 'postmessage'}).then(signInCallback);
});
</script>
</body>
</html>
它在本教程中提到,但我沒有得到document.write
我把回調函數。 另外,有沒有辦法可以在登錄成功後擁有用戶的用戶名?
嘗試登錄的結果相反,'的console.log(authResult);',並檢查輸出在開發工具中(按F12)。有沒有迴應? – Tholle
試過了,什麼都沒有。這就像它從來沒有得到這個功能 – Javi
嗯,令人沮喪。您確定您已將'http:// localhost:8080'分配給Developers Console中的'JavaScript origins',並刪除了重定向網址嗎? https://console.developers.google.com/ – Tholle