Google Calendar API V3 - 如何将重复活动复制到其他日历?

时间:2018-05-21 16:57:15

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

我编写了一个GAS,使用API​​ V3将日历范围内的所有事件从一个日历复制到另一个日历。到现在为止还挺好。 问题是管理重复事件,因为recurringEventId属性可能无法手动管理。基本上在源日历上重复发生的事件在新日历中被视为单个事件,recurringEventId不能更改为"不可变"。

有什么想法吗?

类似于:Google Calendar API V3: Recurring Event Edits

function DuplicateCalendars() {
  var calendarIdFrom = 'xxxxxxxxxxxxx@group.calendar.google.com'; 
  var calendarIdTo = 'yyyyyyyyyyyyyy@group.calendar.google.com'; 
  // August 31, 2017 08:00:00 AM
  var start = new Date("2017-08-31T00:01:00Z");
  // August 30, 2018 11:30:00 PM
  var end = new Date("2018-08-31T00:00:00Z");
  var optionalArgs = {
    timeMin: start.toISOString(),
    timeMax: end.toISOString(),
    showDeleted: false,
    singleEvents: true,
    maxResults: 5,
    orderBy: 'startTime'
  };
  var newCalendarEvent;
  var response = Calendar.Events.list(calendarIdFrom, optionalArgs);
  var events = response.items;

  if (events.length > 0) {
    for (i = 0; i < events.length; i++) {
      var event = events[i];
      newCalendarEvent = {
        "created": event.created,
        "summary": event.summary,
        "description": event.description,
        "location": event.location,
        "colorId": event.colorId,
        "creator": event.creator,
        "organizer": event.organizer,
        "start": event.start,
        "end": event.end,
        "endTimeUnspecified": event.endTimeUnspecified,
        "reminders": event.reminders,
        "attachments": event.attachments,
        "recurrence": event.recurrence
      };
      if (typeof event.recurringEventId !== 'undefined'){
        // what can I do????????
      }
      newCalendarEvent = Calendar.Events.insert(newCalendarEvent, calendarIdTo, {
           supportsAttachments: true
      });
    }
  } else {
    Logger.log('No upcoming events found.');
  }
}

0 个答案:

没有答案