Google 日历 API - 创建活动 PHP

Google Calendar API - create event PHP

我想使用 Google 日历 API 在 Google 日历中插入一个新事件。 问题是我想根据输入的日期时间数据将事件状态设置为“空闲”或“忙碌”。

如何将活动状态更改为“免费”?当我创建一个新事件时,它会自动设置为“忙碌”。我不知道如何设置为“空闲”或“忙碌”。

如何使用 Google 日历 API.

插入新事件
$googleClient = new GoogleClient();
$slotCalendarService = GoogleClientCalendar::getSlotCalendar($googleClient->getClient());

$googleEvent = new Event();

$googleEventStart = new EventDateTime();
$googleEventStart->setTimeZone($attrs['timezone']);
$googleEventStart->setDateTime("2021-12-02T10:00:00");
$googleEvent->setStart($googleEventStart);

$googleEventEnd = new EventDateTime();
$googleEventEnd->setTimeZone($attrs['timezone']);
$googleEventEnd->setDateTime("2021-12-02T10:50:00");
$googleEvent->setEnd($googleEventEnd);

$googleEventAttendee = new EventAttendee();
$googleEventAttendee->email = empty($attrs['attendee']) ? '' : $attrs['attendee'];
$googleEvent->description = $description;
$googleEvent->summary = $remark;
$googleEvent->setAttendees($googleEventAttendee);
$slotCalendarService->getCalendarService()->events->insert($slotCalendarService->getCurrentCalendarId(), $googleEvent);

基于上面的代码,没有设置事件状态为“空闲”或“忙碌”的参数。 我也关注文档 FreeBusy Google Calendar API,但它没有关于如何将事件状态设置为“空闲”或“忙碌”的信息。

当您想设置为“免费”时,请修改如下。

发件人:

$googleEvent->setAttendees($googleEventAttendee);
$slotCalendarService->getCalendarService()->events->insert($slotCalendarService->getCurrentCalendarId(), $googleEvent);

收件人:

$googleEvent->setAttendees($googleEventAttendee);
$googleEvent->transparency = "transparent"; // Added
$slotCalendarService->getCalendarService()->events->insert($slotCalendarService->getCurrentCalendarId(), $googleEvent);
  • 当您不使用 $googleEvent->transparency = "transparent"; 或使用 $googleEvent->transparency = "opaque"; 时,它是“忙”。

参考: