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