如何使用Google Script将日历活动复制(复制)到另一个日历?

时间:2012-09-19 14:46:03

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

我在Google日历中有几个日历。我正在学习Google Script,并希望创建一个脚本,将事件从我的一个日历复制到另一个日历,并有机会修改重复等参数。

2 个答案:

答案 0 :(得分:2)

一些代码开头:

function myFunction() {
  var calendarSource = CalendarApp.getCalendarById("calendarID");
  var calendarDestination = CalendarApp.getCalendarById("calendarID");
  var eventToCopy = calendarSource.getEvents(new Date("July 21, 2009 EST"), new Date("July 22, 2009 EST"));

  //read up: https://developers.google.com/apps-script/class_recurrence
  var newRecurrence = CalendarApp.newRecurrence().addWeeklyRule().times(10);

  for (var i in eventToCopy){
    if (eventToCopy[i].getTitle() == "event name"){
      var newEvent = calendarDestination.createEventSeries(eventToCopy[i].getTitle(), eventToCopy[i].getStartTime(), eventToCopy[i].getEndTime(), newRecurrence);
    }

}

这应该让你开始,

答案 1 :(得分:2)

这是一个旧线程,但这里是如何获取重复字段:

function test_allEventsFromTo() {
  var events = allEventsFromTo("primary", "1 feb 2018", "1 jul 2018");

  //display
  Logger.log("Events #%s\n", events.length);
  for (var i = 0; i < events.length; i++) {
    Logger.log("Title: %s, From: %s, To: %s, recurrence: %s", 
                events[i].summary, events[i].start.dateTime, events[i].end.dateTime, events[i].recurrence);
  }
}


function allEventsFromTo(calendarId, startDate, endDate) { 
  //filter setup
  var optionalArgs = {
    timeMin: (new Date(startDate)).toISOString(),
    timeMax: (new Date(endDate)).toISOString(),
    showDeleted: false,
    singleEvents: false,  //true expands recurring events
  };

  //Filter by calendarId and date range
  var response = Calendar.Events.list(calendarId, optionalArgs);

  return response.items;
}

有关活动的更多信息:

事件,资源代表: https://developers.google.com/calendar/v3/reference/events

重复字段字符串格式: https://developers.google.com/calendar/concepts/events-calendars#recurring_events