google-apps-script google calendar null事件

时间:2018-06-01 16:48:05

标签: google-apps-script google-calendar-api

我不明白为什么“event”总是返回null,我不确定我做错了什么并且无法在文档中找到任何内容。

var cal_id = "xxxxxxxxxxx@group.calendar.google.com";
var start = new Date();
var calendar = CalendarApp.getCalendarById(cal_id);
var end = new Date(new Date().setFullYear(new Date().getFullYear() + 3)); 
var calendar = CalendarApp.getCalendarById(cal_id);
var events = calendar.getEvents(start, end);
var event_id = events[0].getId();
var event = calendar.getEventById(event_id) 

1 个答案:

答案 0 :(得分:0)

我使用var event = events[0];并且根本不使用getId()来处理它。最终的代码与此类似:

var cal_id = "xxxxxxxxxxx@group.calendar.google.com";
var start = new Date();
var calendar = CalendarApp.getCalendarById(cal_id);
var end = new Date(new Date().setFullYear(new Date().getFullYear() + 3)); 
var calendar = CalendarApp.getCalendarById(cal_id);
var events = calendar.getEvents(start, end);
var event = events[0];