【发布时间】:2014-12-27 04:01:24
【问题描述】:
我正在尝试遵循 Google's developer tutorial 中的示例示例
使用更新的 chrome(版本 38.0)
但似乎 gapi.auth 函数从未到达其回调
这是一个演示它的代码示例:
<!doctype html>
<html>
<head>
<title>Google API Client test</title>
</head>
<body>
here will be the use of Oauth 2.0
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
googleApiClientReady = function() {
window.setTimeout(checkAuth, 1);
}
function checkAuth() {
gapi.auth.authorize({
client_id: 'XXX',
scope: 'https://www.googleapis.com/auth/youtube',
immediate: true
}, handleAuthResult);
}
function handleAuthResult(authResult) {
if (authResult && !authResult.error) {
alert('gapi.auth return successfully');
} else {
alert('gapi.auth return with error');
}
}
</script>
<script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>
</body>
</html>
当我运行上面的 html+JS 文件时 - none 的 2 个 'HandleAuthResult' 可选警报显示在屏幕上at all - 这意味着此功能不被“gapi.auth.authorize”回调
有人设法正确使用这个库吗?
【问题讨论】:
标签: javascript oauth oauth-2.0 google-api google-api-client