如何更新 Google 日历事件中的与会者列表?
How to update attendees list in Google Calendar Event?
以下代码用于更新标题、详细信息和位置:
$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']),
),
),
));
有人知道更新与会者的信息吗?
我相信你的目标如下。
- 您想使用带有 PHP 的 googleapis 更新活动中的与会者。
- 您已经能够使用 Calendar API.
获取和放置 Google Calendar 的值
为此,这个答案怎么样?在这种情况下,我建议使用Events: patch in Calendar API.
的方法
示例脚本:
$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
时,现有活动的参加者将被覆盖。所以请注意这一点。所以我建议使用示例事件来测试上面的脚本。
参考:
以下代码用于更新标题、详细信息和位置:
$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']),
),
),
));
有人知道更新与会者的信息吗?
我相信你的目标如下。
- 您想使用带有 PHP 的 googleapis 更新活动中的与会者。
- 您已经能够使用 Calendar API. 获取和放置 Google Calendar 的值
为此,这个答案怎么样?在这种情况下,我建议使用Events: patch in Calendar API.
的方法示例脚本:
$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
时,现有活动的参加者将被覆盖。所以请注意这一点。所以我建议使用示例事件来测试上面的脚本。