I'm attempting to rewrite a legacy application which I didn't write previously using the Google Calendar v3 API.
I've implemented the google-api-php-client, created an API key in my developer console and gone through the process to authenticate. I've got an accessToken
which I'm persisting in the database and when it expires, I can refresh that token fine.
However, I'm unable to any work with the Calendars at all.
I'm following what limited documentation is already out there and have the following:
$this->client = new Google_Client();
$this->client->setClientId( $this->settings['clientId'] );
$this->client->setClientSecret( $this->settings['clientSecret'] );
$this->client->setAccessToken( $this->settings['accessToken'] );
$service = new Google_Service_Calendar($this->client);
$calendarList = $service->calendarList->listCalendarList();
while(true) {
foreach ($calendarList->getItems() as $calendarListEntry) {
echo $calendarListEntry->getSummary();
}
$pageToken = $calendarList->getNextPageToken();
if ($pageToken) {
$optParams = array('pageToken' => $pageToken);
$calendarList = $service->calendarList->listCalendarList($optParams);
} else {
break;
}
}
The error that I'm getting back is :
Message: Undefined property: Google_Service_Calendar_CalendarList::$items
I've checked my Google Calendar account and all the calendars are shared, so there should be no problem, although I don't see why that is an issue since I'm using an authenticated account anyway.
Anyone able to offer advice?
Many Thanks
The Error you are getting
Message: Undefined property: Google_Service_Calendar_CalendarList::$items
Is because the object is empty
Replace
while(true) {
foreach ($calendarList->getItems() as $calendarListEntry) {
echo $calendarListEntry->getSummary();
}Undefined property
with this to get rid of the error.
if ($calendarList->getItems()) {
foreach ($calendarList->getItems() as $calendarListEntry) {
echo $calendarListEntry->getSummary();
}
Also adjust the following
$this->client = new Google_Client();
Needs to be
$client = new Google_Client();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With