I’m having trouble with my PHP implementation for Google Calendar API integration. I found a solution online and followed the steps but when I run the code nothing happens at all.
Here’s what I’m trying to do:
<?php
require_once './google-calendar-sdk/vendor/autoload.php';
$googleClient = new Google_Client();
$googleClient->addScope("https://www.googleapis.com/auth/calendar.readonly");
$googleClient->setAuthConfig('credentials.json');
$calendarService = new Google_Service_Calendar($googleClient);
$calendarData = $calendarService->calendarList->listCalendarList();
while(true) {
foreach ($calendarData->getItems() as $calendar) {
echo $calendar->getSummary();
echo "\n------------------------------\n\n";
// fetch events
$eventsList = $calendarService->events->listEvents($calendar->id);
foreach ($eventsList->getItems() as $calendarEvent) {
echo "- " . $calendarEvent->getSummary() . "\n";
echo "- " . $calendarEvent->getStart()->getDateTime() . "\n\n";
}
}
$nextPage = $calendarData->getNextPageToken();
if ($nextPage) {
$params = array('pageToken' => $nextPage);
$calendarData = $calendarService->calendarList->listCalendarList($params);
} else {
break;
}
}
?>
The script runs but produces no output and no errors.
I tried using different versions of the Google API client library but still get the same blank result. Any ideas where I should look for the problem? I must be missing something obvious but can’t figure out what it is.