【发布时间】:2014-05-29 01:16:37
【问题描述】:
我正在编写一个脚本,它将从 Google 日历中提取一天的事件,并最终制作一个电子邮件议程。我正在改编来自https://developers.google.com/apps-script/templates 的sn-p。
// Get today's events
var now = new Date();
var morning = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
var night = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999)
var cals = [[in the real code, this contains about 30 valid, properly structured calendar IDs with commas and single quotes in all the right places]];
Logger.log(cals.length); //double-checking number to ensure that I didn't miss a calendar
//cycle through calendars and get events
var events = [];
var working;
var currentCal;
for (var i=0; i<cals.length; i++){
currentCal = cals[i];
working = CalendarApp.getCalendarById(currentCal).getEvents(morning,night);
Logger.log(working.getTitle());
events.push(working[0]);
}
Logger.log(events);
我在倒数第二个 Logger.log 调用中尝试了各种策略。最初,它只是记录工作。问题是,我无法让它停止记录“CalendarEvent”——字符串,字面意思,就像它在这里一样——而不是实际的日历事件。事件记录为空数组和偶尔的“CalendarEvent”。我怀疑我在这里忽略了一些愚蠢的东西,比如“工作”的对象类型实际上是。
那么,CalendarEvent 应该是一个什么样的对象呢?正如我所怀疑的那样,它是它自己的结构化事物,还是只是一个包含事件标题、时间、描述等的数组? (如您在上面看到的,我尝试将其视为一个数组,但无济于事。)
【问题讨论】:
-
在控制台
console.log(cals)运行,你会看到结构。 -
我刚试过。正如我所期望的那样,它输出日历 ID 数组。事件仍然记录为 [null, null, CalendarEvent, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null ,空,空,空,空,空,空,空,空,空]。
-
实际上,CalendarEvent 甚至不应该存在 - 今天的任何日历上都没有事件。
-
猜你没有得到很好的回应。日历事件应该是这样的developers.google.com/google-apps/calendar/v3/reference/…
-
不过,这看起来像是针对 API 的。日历事件的 API 版本和 Google Apps 脚本版本之间有区别吗?好消息是,它现在只在实际有一个数组时才将“CalendarEvent”放入该数组,但 thatArray.toString() == '' 仍然评估为真。
标签: javascript google-apps-script google-calendar-api