0

アプリをGoogleカレンダーと同期する2つの方法を実現しようとしています。繰り返しイベントがどのように機能するかについての合理的な説明が見つかりませんでした。それらはメイン イベント内で物理的に複製されていますか (独自の ID を持っていますか)。Google カレンダー API (listEvents) は、繰り返しのあるメイン イベントのみを返します (文字列)。繰り返しに独自の ID がない場合、それらを削除するにはどうすればよいですか? API(listEvents)からのデータでシリーズ(Googleカレンダー)から1つの定期的なイベントを削除すると、その定期的なイベントが欠落しているという言及はありません。

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

例外を追加する (繰り返しイベントのインスタンスを 1 つだけ削除する) 場合は、ほぼ同じコードを使用する必要がありますが、別のフィルターを使用する必要があります。

    $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 に答える