php - 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."
}
}
额外细节:
- 我正在使用启用了域范围委派的服务帐户
解决方案
显然您忘记在您的请求中添加 requestID。
"conferenceData": {
"createRequest": {
"conferenceSolutionKey": {
"type": "eventHangout"
},
"requestId": "yourcodehere"
}
}
您可以通过向createRequest提供新生成的requestId(可以是随机字符串)来为事件创建新会议。会议是异步创建的,但您始终可以检查您的请求状态,让您的用户知道发生了什么。
我希望这会有所帮助。
推荐阅读
- docker - 在 nginx 反向代理后面运行 Camunda Operate dockerized
- python - Python如何获取用property.setter包装的方法的__qualname__
- r - 如何使用 ggplot 在 R 散点图中更好地标记数据点
- r - 您如何处理分区中的错误?
- sparql - 在 fuseki 中编辑示例查询
- javascript - 在 vue.js 中访问 v-for 列表项对象数据
- android - 单击 Spinner 时出现 IndexOutOfBoundsException
- php - 查找节点路径(地图/城市)的“子路径”的算法
- android - 使用retrofit2发送带有身体模型的多部分
- python-3.x - 在 3D 矩阵中沿单个轴滚动不同量