【问题标题】:Google Calendar API, how to add an event with attached newly generated google meet?Google Calendar API,如何添加带有附加新生成的google meet的事件?
【发布时间】:2021-03-12 20:55:11
【问题描述】:

我正在尝试了解如何在 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),因此它们存在。在文档中有一个 javacript 示例,但我不知道如何将其转换为 php 代码。

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

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

这里有一个关于它的使用的简短文档:

API客户端支持的会议数据版本号。版本 0 假定不支持会议数据并忽略事件正文中的会议数据。版本 1 支持复制会议数据以及使用会议数据的 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);

有什么建议吗?

【问题讨论】:

    标签: php google-calendar-api google-meet


    【解决方案1】:

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

    • 您想使用 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));
    

    参考资料:

    【讨论】:

    • 非常感谢,您的回答解决了我的问题。
    • @Peter 感谢您的回复。很高兴您的问题得到解决。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多