>我将日历与外部应用程序同步。我必须在此应用程序和Google日历中具有相同的事件ID。但在此应用程序中,删除事件后,其 ID 可用于将来的新事件。所以我希望,当我使用日历 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); }
但是此代码返回消息"禁止",代码为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);
如果有人对我有想法,那就太好了!
谢谢。
我有一个解决你的问题的解决方法。我的步骤是:
- 创建新日历
- 将事件移动到日历
- 删除日历
据我所知,日历没有垃圾...
$calendar = new Google_Service_Calendar_Calendar();
$calendar->setSummary('calendarSummary');
$calendar->setTimeZone('America/Los_Angeles');
$createdCalendar = $service->calendars->insert($calendar);
$result = $service->events->move('primary', 'eventId', $createdCalendar->getId());
$service->calendars->delete($createdCalendar->getId());
对不起,我在PHP上的技能很差
请注意日历限制(目前为60,在此处阅读更多相关信息:https://support.google.com/a/answer/2905486?hl=en(