谷歌日历API,如何添加一个事件与附加的新生成的谷歌会议



我正在尝试了解如何用PHP生成并附加到Google日历事件的Google Meet istance。

文件(https://developers.google.com/calendar/create-events#conferencing)不清楚这一部分,PHP的类和方法都有文档(https://developers.google.com/resources/api-libraries/documentation/calendar/v3/php/latest/class-Google_Service_Calendar_CreateConferenceRequest.html)所以它们存在。在文档中有一个javascript示例,但我不知道如何将其转换为php代码。

我在谷歌上搜索了一下,但以前似乎没有人有这种必要。

更新:我想我发现了问题。javascript文档报告需要setDocumentDataVersion(1(才能处理Meetings。

这里有一个关于其用途的简短文档:

API客户端支持的会议数据的版本号。版本0假定不支持会议数据,并忽略事件正文中的会议数据。版本1支持复制ConferenceData以及使用ConferenceData的createRequest字段创建新会议。默认值为0。

此方法似乎不存在于PHP API中,因此我无法将其设置为1。这可能就是为什么我的代码无法将谷歌会议附加到我的活动中的原因。

这是我的测试代码。到目前为止,它运行良好,并在我的日历中创建了一个事件。

# Booking
$calendarId = 'test@group.calendar.google.com'; #
$event = new Google_Service_Calendar_Event();
$event->setSummary('Test');
$event->setDescription('Test Test');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2020-11-30T19:00:00+01:00');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2020-11-30T19:20:00+01:00');
$event->setEnd($end);
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('mytestemail@testtest.com');
// ...
$attendees = array($attendee1,
// ...
);
$event->attendees = $attendees;
#Try to create a Google Meet and attach it to event
$solution_key = new Google_Service_Calendar_ConferenceSolutionKey();
$solution_key->setType("hangoutsMeet");
$confrequest = new Google_Service_Calendar_CreateConferenceRequest();
$confrequest->setRequestId("3whatisup3");
$confrequest->setConferenceSolutionKey($solution_key);
$confdata = new Google_Service_Calendar_ConferenceData();
$confdata->setCreateRequest($confrequest);
$event->setConferenceData($confdata);

$createdEvent = $service->events->insert($calendarId, $event);

有什么建议吗?

我相信你的目标和情况如下。

  • 您想使用googleapisforphp在GoogleMeet中创建新的活动
  • 您已经能够使用日历API创建新事件

为了将Google Meet添加到脚本,设置了conferenceDataVersion。在这种情况下,插入方法似乎是insert( string $calendarId, Google_Service_Calendar_Event $postBody, array $optParams = array() )。因此,请按如下方式修改您的脚本。

发件人:

$createdEvent = $service->events->insert($calendarId, $event);

收件人:

$createdEvent = $service->events->insert($calendarId, $event, array('conferenceDataVersion' => 1));

参考文献:

  • 事件:插入
  • 类Google_Services_Calendar_Events_Resource

最新更新