Warm tip: This article is reproduced from serverfault.com, please click

php-Google Calendar API,如何添加带有新生成的Google Meet的事件?

(php - Google Calendar API, how to add an event with attached newly generated google meet?)

发布于 2020-11-30 22:19:45

我想了解如何生成PHP中的Google Meet实例并将其附加到Google Calendar Event。

关于此部分,文档(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),以便它们存在。在文档中有一个javacript示例,但我不知道如何将其转换为php代码。

我做了一些谷歌搜索,但似乎没有其他人以前有这种必要。

更新:我想我已经找到问题了。javascript文档报告需要setDocumentDataVersion(1)才能处理会议。

以下是有关其用法的简要文档:

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

此方法似乎在PHP API中不存在,因此无法将其设置为1。这可能就是为什么我的代码无法将Google Meet与我的活动相关联的原因。

这是我的测试代码。到这里为止一切正常,并在我的日历中创建了一个活动。

# 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);

有什么建议么?

Questioner
Peter
Viewed
0
Tanaike 2020-12-01 07:31:16

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

  • 你想使用googleapis for php与Google Meet创建新活动。
  • 你已经能够使用Calendar 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));

参考: