0
votes

I am using the Google API PHP client with Google Calendar.

I am having now problems creating the event, but when I try to update the datetime start/end the call just fails and the event is not updated.

I have successfully updated just the summary, but have been unable to update the start/end times.

private function _update_google_event($eventId = '', $updateData = array())
{
if(strlen($eventId) == 0 || empty($updateData)) return false;

$calendar = $this->_get_gcal();
//First get the event
$event = $calendar->events->get($this->calendar_id, $eventId);
var_dump($event->getId());

if(isset($updateData['summary'])) {
  $event->setSummary($updateData['summary']);
}
if(isset($updateData['location'])) {
  $event->setLocation($updateData['location']);
}
var_dump($event->getEnd());
/*
if(isset($updateData['start'])) {
  $start = new Google_Service_Calendar_EventDateTime();
  $start->setDateTime($updateData['start']);
  $event->setStart($start);
}
*/
if(isset($updateData['end'])) {
  var_dump(new Google_EventDateTime());
  $end = new Google_Service_Calendar_EventDateTime();
  var_dump($end->setDateTime($updateData['end']));
  $end->setDateTime($updateData['end']);
  var_dump($event->setEnd($end));
}

//Update Sequence
$event->setSequence($event->getSequence() + 1);

echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
//var_dump($event);
//Send the update request
//$updatedEvent = new Google_Service_Calendar_Event($calendar->events->update($this->calendar_id, $event->getId(), $event));
$updatedEvent = $calendar->events->update($this->calendar_id, $event->getId(), $event);
echo $updatedEvent->getUpdated();

return false;
}

I have seen some stack overflow questions on updating events that mentioned needing to update the sequence number, so I have done so, but it does not change anything for start/end time.

Any tips/pointers would be much appreciated. If any other details can help, please just ask.

Thank you!

1

1 Answers

1
votes

I realized my problem was not in the function, but in the data that I'm passing itself.

$updateData['start'] and $updateData['end'] was being passed as a DateTime object. I resolved it by using DateTime::format and then passing it into the function.