0

I'm getting an error at the setSummary line in my code below. I included Google's example code. Is this a bug or is there something wrong with my code?

$event = new Event();
$task = $tasks[0];
if (!empty($refreshToken) && !empty($calendarId)) {
$client->refreshToken($refreshToken);
if (!empty($task[145])) {
    $event = $calendarServer->events->get($calendarId, $task[145]);
}
$event->setSummary('test string');

Example Google Code from https://developers.google.com/google-apps/calendar/v3/reference/events/update

$event = $service->events->get('primary', 'eventId');
$event->setSummary('Appointment at Somewhere');
$updatedEvent = $service->events->update('primary', $event->getId(), $event);
echo $updatedEvent->getUpdated();

My script is breaking at the line setSummary with error: ( ! ) Fatal error: Call to a member function setSummary() on a non-object in /vagrant/public/gcalendar/sync.php on line 47

tereško
  • 58,060
  • 25
  • 98
  • 150
kevins
  • 472
  • 6
  • 17

1 Answers1

0

I updated to the newest version of the php sdk, and figured out that I was not properly creating the new "event object" if the event already exists. The following is what I'm currently using.

if (!empty($eventIdString)) {
            $event = new Google_Event($calendarServer->events->get($calendarId, $eventIdString));
    }
    else {
        $event = new Google_Event();
    }
kevins
  • 472
  • 6
  • 17