繁体   English   中英

谷歌日历 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"; ,它是“忙”。

参考:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM