当我看到API的V2版本将在不到一年的时间内被弃用时,我只是一个开发工具,可使用Javascript从Google日历获取事件。那显然毁了我的一天^^。
因此,我尝试熟悉此新API,但是仍然找不到我想要的东西。
如何使用Google Calendar API v3的javascript客户端执行参数“ futureevents = true”的等效操作?
<script type="text/javascript">
var apiKey = 'apikey';
var scopes = 'https://www.googleapis.com/auth/calendar';
function handleClientLoad() {
gapi.client.setApiKey(apiKey);
makeApiCall();
}
function makeApiCall() {
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.events.list({
'calendarId': 'idcalendar@group.calendar.google.com'
});
request.execute(function(resp) {
console.log(resp);
for (var i = 0; i < resp.items.length; i++) {
var title = document.createTextNode(resp.items[i].summary);
var description = document.createTextNode(resp.items[i].description + ' ');
var location = document.createTextNode(resp.items[i].location + ' ');
var date = document.createTextNode('Start: ' + resp.items[i].start.date + ' End: ' + resp.items[i].end.date);
var div = document.createElement('div');
var h1 = document.createElement('h1');
h1.appendChild(title);
div.appendChild(location);
div.appendChild(description);
div.appendChild(h1);
var p = document.createElement('p');
p.appendChild(date);
div.appendChild(p);
document.body.appendChild(h1);
document.body.appendChild(div);
}
});
}
</script>
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
这是我的代码,有了这个,我得到了日历中的所有事件,我如何才能只获得尚未发生的事件。
预先感谢
最佳答案
现在,使用events.list()API调用的timeMin
参数仅请求事件。
var request = gapi.client.calendar.events.list({
'calendarId': 'idcalendar@group.calendar.google.com',
'timeMin': '2013-05-09T09:43:00-04:00'
});
您可能需要使用Date格式,我不确定该值应该是哪种类型,但是您只需要获取当前日期时间并将其发送即可。