2
您好,我的主要目标是从谷歌日历中抓取所有事件,并在下方显示其日期(以及时间,如果可用)的名称。我正在使用JavaScript的谷歌日历api v3,并遇到麻烦抢劫每个事件的日期。在我进一步的解释我的问题是当前的代码:从javascript日历api v3获取活动来自某一天v3
var clientId = '200816328603.apps.googleusercontent.com';
var apiKey = 'AIzaSyD3rbV__d8u6r9u5GioBU0oVwa-53YXRqM';
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;
}
//document.createTextNode(resp.items[i].summary)
function makeApiCall() {
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.events.list({
'calendarId': '[email protected]com'
});
request.execute(function(resp) {
for (var i = 0; i < resp.items.length; i++) {
//---------nodes for html elements
var title = document.createTextNode(resp.items[i].summary); //titles are undefined so I'm using the summary as title instead
//var description = document.createTextNode(resp.items[i].description); //there are no descriptions apparently
var date = document.createTextNode('Start: ' + resp.items[i].start.date + ' End: ' + resp.items[i].end.date); //resp.items[i].date returns undefined
//---------html elements
var div = document.createElement('div');
div.className = resp.items[i].summary;
var h1 = document.createElement('h1');
h1.appendChild(title);
div.appendChild(h1);
//loop is to filter out all the undefined
if (date.textContent != 'Start: undefined End: undefined') {
var p = document.createElement('p');
p.appendChild(date);
div.appendChild(p);
}
document.body.appendChild(div);
}
});
});
}
现在resp.items [I] .start.date和resp.items [I] .end.date偶尔会,但有时返回日期只是返回undefined。那么我还能如何获取活动的日期呢?
我的想法是绕过这个月的每一天,并抓住那一天的所有事件。但是,当我尝试添加RFC3339时间戳的timeMax和timeMin参数为所需的一天它不返回任何东西。有人能为我提供一个实现这个目标的例子吗?
任何帮助,非常感谢。