Skip to content
Advertisement

How to use the Google calendar API’s functions

I’m trying to use the Google calendar API and I can’t properly call the built-in functions. For reference:

$events = $service->events->listEvents('primary');

while(true) {
    foreach ($events->getItems() as $event) {
        echo $event->getSummary();
    }
    $pageToken = $events->getNextPageToken();
    if ($pageToken) {
        $optParams = array('pageToken' => $pageToken);
        $events = $service->events->listEvents('primary', $optParams);
    } else {
        break;
    }
}

This code return a fatal error:

Call to a member function getItems() on a non-object

I don’t understand how to use an object which is not instantiated by a New().

Advertisement

Answer

You need to add this line into your code

$client->setUseObjects(true);
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement