我指的是this question。
作为此代码
var cal = CalendarApp.getCalendarById("Calendar Id");
var startTime = new Date(1850, 0, 1);
var endTime = new Date(2100, 0, 1);
var events = cal.getEvents(startTime, endTime);
Logger.log(events);
var sp = PropertiesService.getScriptProperties();
sp.setProperty("events", JSON.stringify(events));
events = JSON.parse(sp.getProperty("events"));
Logger.log(events);
返回:
Info [CalendarEvent, CalendarEvent, CalendarEvent, CalendarEvent, CalendarEvent]
Info [{}, {}, {}, {}, {}]
如何使用PropertiesService存储和检索CalendarEvent(不仅是ID)?
我认为最好的选择是执行以下操作:
oldEventIDs
)中。allEvents
)检索日历中的所有事件。newEvents
)中已经存在的事件。oldEventIDs
。oldEventIDs
存储在属性中。var sp = PropertiesService.getScriptProperties();
var oldEventIDs = sp.getProperty("events").split(",");
var cal = CalendarApp.getCalendarById("Calendar Id");
var startTime = new Date(1850, 0, 1);
var endTime = new Date(2100, 0, 1);
var allEvents = cal.getEvents(startTime, endTime);
var newEvents = allEvents.filter(event => !oldEventIDs.includes(event.getId()));
newEvents.forEach(event => {
// Event processing
oldEventIDs.push(event.getId());
});
sp.setProperty("events", oldEventIDs.toString());
getEvents
。我看不到如何将事件存储在Properties中可以避免这种情况。这就是从日历中获取事件的方法。无论如何,我认为花费更多时间的是“处理中”事件,有关该事件没有任何信息。