4

我想使用 Google Apps 脚本createAllDayEvent(title, date)创建一个全天谷歌日历,但只有一个日期参数,所以我只能创建一个全天谷歌日历。

现在我需要创建两天的 AllDay Google 日历(例如:从 2013 年 6 月 28 日到 2013 年 6 月 29 日),我该怎么办?

感谢帮助!

4

3 回答 3

3

您需要使用createAllDayEventSeries(),它接受Recurrence参数。

var recurrence = CalendarApp.newRecurrence().addDailyRule().times(2);
var eventSeries = CalendarApp.getDefaultCalendar().createAllDayEventSeries('My All Day Event',
    new Date('June 28, 2013'),
    recurrence,
    {guests: 'everyone@example.com'});
Logger.log('Event Series ID: ' + eventSeries.getId());
于 2013-07-02T14:44:23.983 回答
0

现在似乎可以通过 CalendarApp 类直接使用createAllDayEvent(title, startDate, endDate)

// Creates an all-day event for the Woodstock festival (August 15th to 17th) and logs the ID.
var event = CalendarApp.getDefaultCalendar().createAllDayEvent('Woodstock Festival',
    new Date('August 15, 1969'),
    new Date('August 18, 1969'));
于 2021-10-08T12:21:49.657 回答
0

您无法通过 CalendarApp 类添加创建跨越多天的多天“全天”事件。您必须通过高级 Google 服务使用日历 API 来执行此操作。

1) 为脚本启用日历 API 在 google 脚本页面上,转到菜单项“资源”→“高级 Google 服务”。打开日历 API(当前为 v3)。

2) 通过 Google API 控制台启用服务 在高级 Google 服务页面中,点击 API 控制台的链接。单击“+ 启用 API”。选择“日历 API”,然后启用它。

3) 使用下面的代码片段(创建一个为期两天的全天事件)作为示例

var calId = '##########################@group.calendar.google.com';
var event = {
             "summary":"Summary",
             "location":"Location",
             "description":"Description",
             "start":{
                      "date":"2017-06-03"
                     },
             "end":{
                    "date":"2017-06-05"
                   }
            };
Calendar.Events.insert(event,calId);

// You can check how the events are stored below
var events = Calendar.Events.list(calId, {timeMin: (new Date(2017,5,2)).toISOString(),
                                          timeMax: (new Date(2017,5,10)).toISOString(),
                                          maxResults: 2500});

您会注意到,上面的代码将生成一个从 6 月 3 日到 6 月 4 日的全天事件(结束日期基本上是 2017-06-05T00:00:00)。

您可以添加其他事件属性,在Calendar API/Events/insert页面上有所记录。使用 Calendar.Events.list 来获取事件列表会给你一个想法。

如果您查看日历 API 事件,您会注意到与 iCal 规范有很多重叠之处。

于 2017-06-03T13:20:01.097 回答