3
我试图遵循Google's developer tutorial
样品例如使用更新铬(38.0版)gapi.auth JavaScript命令不执行正确
但好像从来没有达到过的的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文件 - “HandleAuthResult”的2个可选的警报没有在所有屏幕上显示- 这意味着该功能不受“gapi.auth.authorize”
叫回来有没有人设法正确使用这个库?
http://stackoverflow.com/questions/21710842/google-api-in-javascript – GyRo 2014-11-09 04:43:49
谢谢。这很有帮助。另外,它只在我从一个web服务器(url以http启动)运行html而不是直接通过文件系统运行时才起作用。 – GyRo 2014-11-09 14:46:33