user1528423
user1528423

Reputation: 91

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().

Upvotes: 2

Views: 1739

Answers (2)

Dinesh Reddy
Dinesh Reddy

Reputation: 1752

Add it just before the following line

$service = new apiCalendarService($client);

Since

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

returns an array but you need an object here

Upvotes: 0

user1528423
user1528423

Reputation: 91

You need to add this line into your code

$client->setUseObjects(true);

Upvotes: 7

Related Questions