首页 > 解决方案 > Google Calendar API:创建活动时无法设置AllowedConferenceSolutionTypes 以包括hangoutsMeet

问题描述

使用适用于 PHP 的 Google API 客户端库,我正在尝试创建一个新的日历事件并附加一个hangoutsMeet会议。当我尝试这样做时,我收到一条错误消息,指出Invalid conference type value.

使用相同的代码,我可以创建一个新事件并附加一个eventHangout会议。

我明白为什么会收到错误消息:根据 API,我的日历仅支持eventHangout会议类型。

<<<< 2020 年 4 月 3 日编辑 #1

在Andres Duarte的回答之后进行澄清:这仅在我尝试通过 API 创建事件时作为限制出现。当我使用 Google 日历界面手动创建活动时,我可以添加 Google Meet。事实上,这是下拉菜单中显示的唯一会议选项。

>>>>

我的问题是,我如何更新我的日历设置(有或没有 API),以便我可以使用 API 创建带有附加hangoutsMeet会议的事件?

这是一些示例代码来演示我尝试过的内容:

<<<< 2020 年 4 月 3 日编辑 #2

hooman182回答后的澄清:我已经更新了我的代码示例,以证明我requestId使用字符串进行了正确设置。

>>>>

try {


    // fetch the calendar
    $calendar = 'myCalendar';
    $calendarObject = $service->calendars->get($calendar);
    echo "<pre>";
    echo "\nORIGINAL *******************************************************\n\n";
    var_dump($calendarObject->getConferenceProperties()->getAllowedConferenceSolutionTypes());


    // set the allowed conferences solutions type
    $calendarObject->getConferenceProperties()->setAllowedConferenceSolutionTypes(
        array(
            "hangoutsMeet",
            "eventHangout",
            "eventNamedHangout",
        )
    );
    echo "\nUPDATED *******************************************************\n\n";
    var_dump($calendarObject->getConferenceProperties()->getAllowedConferenceSolutionTypes());


    // save the changes to the calendar
    $calendarObject = $service->calendars->patch($calendar, $calendarObject);;
    echo "\nSAVED *********************************************************\n\n";
    var_dump($calendarObject->getConferenceProperties()->getAllowedConferenceSolutionTypes());


    // add a createRequest to my event
    $event->setConferenceData(new Google_Service_Calendar_ConferenceData(array(
        'createRequest' => array(
            'requestId' => md5(time()),
            'conferenceSolutionKey' => array(
                'type' => 'hangoutsMeet',
            )
        )
    )));


    // save the event
    $event = $service->events->insert($calendar, $event, array(
        'conferenceDataVersion' => 1
    ));


} catch (Google_Service_Exception $e) {

    echo "\nERRORS ********************************************************\n\n";
    var_dump($e->getErrors());
    die;

}

这是上面的输出:

ORIGINAL *******************************************************

array(1) {
  [0]=>
  string(12) "eventHangout"
}

UPDATED *******************************************************

array(3) {
  [0]=>
  string(12) "hangoutsMeet"
  [1]=>
  string(12) "eventHangout"
  [2]=>
  string(17) "eventNamedHangout"
}

SAVED *********************************************************

array(1) {
  [0]=>
  string(12) "eventHangout"
}

ERRORS ********************************************************

array(1) {
  [0]=>
  array(3) {
    ["domain"]=>
    string(6) "global"
    ["reason"]=>
    string(7) "invalid"
    ["message"]=>
    string(30) "Invalid conference type value."
  }
}

额外细节:

标签: phpgoogle-calendar-apigoogle-api-php-client

解决方案


显然您忘记在您的请求中添加 requestID。

资源:将视频和电话会议添加到活动中

 "conferenceData": {
    "createRequest": {
      "conferenceSolutionKey": {
        "type": "eventHangout"
      },
      "requestId": "yourcodehere"
    }
  }

您可以通过向createRequest提供新生成的requestId(可以是随机字符串)来为事件创建新会议。会议是异步创建的,但您始终可以检查您的请求状态,让您的用户知道发生了什么。

我希望这会有所帮助。


推荐阅读