2013-12-13 69 views
0

我嘗試實現兩種方式將應用與Google日曆同步。我沒有找到合理的描述重現事件如何工作。他們是否在主要活動中重複(有自己的ID)? Google日曆API(listEvents)僅返回帶重複事件的主要事件(字符串)。當復發沒有自己的ID時,我如何刪除它們?當我從API(listEvents)的數據中刪除系列中的一個重複事件(在谷歌日曆中)時,沒有提到關於該遺漏的重複事件。谷歌日曆工作中的重複事件

回答

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()); 
     } 
    } 

如果你想添加例外(刪除複發性事件只有一個實例),需要使用幾乎相同的代碼,但與其他過濾接r:

$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()); 
     } 
    }