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