我正在尝试运行以下 Google Api 示例:
<:html:>
<:body:>
<:div id='content':>
<:h1:>Events<:/h1:>
<:ul id='events':><:/ul:>
<:/div:>
<:a href='#' id='authorize-button' onclick='handleAuthClick();':>Login<:/a:>
<:script:>
var clientId = redacted;
var apiKey = redacted;
var scopes = 'https://www.googleapis.com/auth/calendar';
function handleClientLoad() {
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth,1);
checkAuth();
}
function checkAuth() {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},
handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById('authorize-button');
if (authResult) {
authorizeButton.style.visibility = 'hidden';
makeApiCall();
} else {
authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
}
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: clientId, scope: scopes, immediate: false},
handleAuthResult);
return false;
}
function makeApiCall() {
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.events.list({
'calendarId': 'primary'
});
request.execute(function(resp) {
for (var i = 0; i <: resp.items.length; i++) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(resp.items[i].summary));
document.getElementById('events').appendChild(li);
}
});
});
}
<:/script:>
<:script src="https://apis.google.com/js/client.js?onload=handleClientLoad":><:/script:>
<:/body:>
<:/html:>
每当我运行该文件时,我都会收到两个错误:
gapi.client 对象为 null 或未定义
window.sessionStorage.length 对象为 null 或未定义
对于最后一个错误,它将此网址作为来源: https://apis.google.com/ /scs/apps-static/ /js/k=oz.gapi.nl.4xKjGS6fluU.O/m=client/am= QQ/rt=j/d=1/rs=AItRSTMdnq2AHV2okN-h3tZllkPQibG86w/cb=gapi.loaded_0
我正在运行 IE8,有人知道出了什么问题吗?