php - 如何在 Google 日历活动中更新与会者列表?
问题描述
下面的代码用于更新标题、详细信息和位置:
$event->setSummary($_POST['title']);
$event->setDescription($_POST['detail']);
$event->setLocation($_POST['location']);
下面的代码是更新日期(开始和结束):
$start = new Google_Service_Calendar_EventDateTime();
$start->setTimeZone($timezone);
$start->setDateTime($startDateTime);
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setTimeZone($timezone);
$end->setDateTime($endDateTime);
$event->setEnd($end);
但我正在努力更新与会者名单。对于插入一个如下:
$people = $_POST['people']; // POST from other webpage
$finalpeople = [];
foreach ($people as $person) {
$finalpeople[] = ['email' => $person];
}
$data['result'] = $finalpeople;
// just look at the attendees one
$event = new Google_Service_Calendar_Event(array(
'id'=> $idFinal,
'summary' => $_POST['title'],
'location' => $_POST['location'],
'description' => $_POST['detail'],
'start' => array(
'dateTime' => $startDateTime,
'timeZone' => $_POST['timezone'],
),
'end' => array(
'dateTime' => $endDateTime,
'timeZone' => $_POST['timezone'],
),
'attendees' => $data['result'],
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => $_POST['reminder']),
),
),
));
任何人有任何想法更新与会者?
解决方案
我相信你的目标如下。
- 您想要使用 googleapis 和 PHP 更新活动中的参与者。
- 您已经能够使用 Calendar API 获取和放置 Google Calendar 的值。
为此,这个答案怎么样?在这种情况下,我建议在 Calendar API 中使用 Events: patch 的方法。
示例脚本:
$client = getClient();
$calendar = new Google_Service_Calendar($client);
$calendarId = "###"; // Please set the calendar ID.
$eventId = "###"; // Please set the event ID.
// Here, please set the new attendees.
$newAttendees = [
array(
'email' => '###',
'comment' => 'sample 1'
),
array(
'email' => '###',
'comment' => 'sample 2'
)
];
$event = new Google_Service_Calendar_Event;
$event->attendees = $newAttendees;
$result = $calendar->events->patch($calendarId, $eventId, $event);
笔记:
- 当您使用
$newAttendees
时,现有活动的参加者将被覆盖。所以请注意这一点。所以我建议使用示例事件来测试上述脚本。
参考:
推荐阅读
- vue.js - 为什么我的 vuejs 组件的挂载钩子不能引用同一组件中的某些方法?
- symfony - Symfony 4 生产 WebProfiler 路由
- c# - WPF 根据数据上下文值隐藏和显示按钮
- java - XSD“属性已定义”
- c# - 刚刚分配对象时的 Unity NullReferenceException
- python - X[y==0,1] 操作在代码中做了什么?
- rust - Rust 函数返回包含参数引用的对象编译正常,但当 &self 包含在参数列表中时编译失败
- r - 当 tmap 工作正常时,如何解决 ggplot 中缺少变量的问题?
- python - 从具有索引的 numpy 数组中绘制随机样本
- driver - 操作系统开发 - 页面错误处理和磁盘驱动程序