Reputation: 45
This code below is to update title, detail, and location:
$event->setSummary($_POST['title']);
$event->setDescription($_POST['detail']);
$event->setLocation($_POST['location']);
This code below is to update date (start and end):
$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);
But I'm struggling to update the attendees list. For the insert one is below:
$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']),
),
),
));
Anyone have any idea to update the attendees?
Upvotes: 1
Views: 998
Reputation: 201358
I believe your goal as follows.
For this, how about this answer? In this case, I would like to propose to use the method of 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
, the attendees of the existing event are overwritten. So please be careful this. So I recommend to use a sample event for testing above script.Upvotes: 1