0

我尝试实现两种方式将应用程序与谷歌日历同步。我没有找到合理的描述重复事件如何工作。他们在主赛事中是否物理复制(有自己的 ID)?Google 日历 API (listEvents) 仅返回带有重复的主要事件(字符串)。当重复没有自己的 ID 时,如何删除它们?当我从 API (listEvents) 的数据中的系列(在谷歌日历中)删除一个重复事件时,没有提到丢失的重复事件。

4

1 回答 1

1

重复事件是一系列单个事件(实例)。您可以通过以下链接了解实例:https ://developers.google.com/google-apps/calendar/v3/reference/events/instances

如果要删除重复事件(所有实例),则需要使用以下代码:

$rec_event = $this->calendar->events->get('primary', $google_event_id);
if ($rec_event && $rec_event->getStatus() != "cancelled") { 
    $this->calendar->events->delete('primary', $google_event_id); // $google_event_id is id of main event with recurrences
}

如果要从某个日期删除所有以下实例,则需要获取该日期之后的所有实例,然后循环删除它们:

    $opt_params = array('timeMin' => $isoDate); // date of DATE_RFC3339 format,  "Y-m-d\TH:i:sP"
    $instances = $this->calendar->events->instances($this->calendar_id, $google_event_id, $opt_params);

    if ($instances && count($instances->getItems())) {
      foreach ($instances->getItems() as $instance) {
        $this->calendar->events->delete('primary', $instance->getId());
      }
    }

如果要添加异常(仅删除重复事件的一个实例)需要使用几乎相同的代码但使用另一个过滤器:

    $opt_params = array('originalStart' => $isoDate); // exception date
    $instances = $this->calendar->events->instances($this->calendar_id, $google_event_id, $opt_params);

    if ($instances && count($instances->getItems())) {
      foreach ($instances->getItems() as $instance) {
        $this->calendar->events->delete('primary', $instance->getId());
      }
    }
于 2014-04-24T13:37:50.190 回答