我将日历与外部应用程序同步。我必须在此应用程序和Google日历中拥有相同的事件ID。但是在此应用程序中,删除事件时,其ID可用于将来的新事件。我喜欢这样,当我使用Calendar API删除活动时,该活动的ID可用。但它总是留在垃圾桶里,我无法用API清空它。
所以,我找到的两个解决方案是:
使用clear
功能:
$cld = $service->calendars->get($calendarId);
$calendarList = $service->calendarList->listCalendarList()->getItems();
$summary = $cld->getSummary();
$timeZone = $cld->getTimeZone();
$events = $service->events->listEvents("primary")->getItems();
$service->calendars->clear('primary');
$cld->setSummary($summary);
$cld->setTimeZone($timeZone);
foreach($events as $event){
$service->events->insert("primary", $event);
}
但是此代码返回消息" Forbidden"代码403在$service->calendars->clear('primary');
创建新日历并将其设为primary
$cld = $service->calendars->get($calendarId);
$calendarList = $service->calendarList->listCalendarList()->getItems();
$summary = $cld->getSummary();
$timeZone = $cld->getTimeZone();
$events = $service->events->listEvents("primary")->getItems();
$calendarListEntry = new Google_Service_Calendar_CalendarListEntry();
$calendarListEntry->setId("account_mail@gmail.com");
$calendarListEntry->setSummary($summary);
$calendarListEntry->setTimeZone($timeZone);
$createdCalendarListEntry = $service->calendarList->insert($calendarListEntry);
foreach($events as $event){
$service->events->insert("account_mail@gmail.com", $event);
}
但是此代码返回消息"无效值"代码400在$createdCalendarListEntry = $service->calendarList->insert($calendarListEntry);
如果某人有我的想法,那就太棒了!
谢谢。