I have created a service account to access a certain google calendar. this service account user also got the permission in the calendar settings as is described in this blog: "allow my user to add meeting in my calendar with Google Calendar API with PHP without auth".
As I can see in Google Cloud Platform under APIs + Services -> Credentials in the Service Account section the created service account is used with all services (last 30 days) every time, when I fire this php script, but in the browser window I get no error, that there would be a problem with authentication but: Uncaught Error: Call to a member function getSummary() on null in line... of the php-script Script and Settings in Google Cloud Platform are as described in the mentioned post.
Any idea what could be the problem? Has there anything changed with google calendar api since this post in 2019?
require '../google-api-php-client/vendor/autoload.php';
ini_set('display_errors', 1);
$client = new Google_Client();
$client->addScope("https://www.googleapis.com/auth/calendar");
$client->setAuthConfig(dirname(__FILE__).'/credentials/credentials.json');
$service = new Google_Service_Calendar($client);
$calendarList = $service->calendarList->listCalendarList();
while(true) {
foreach ($calendarList->getItems() as $calendarListEntry) {
echo $calendarListEntry->getSummary();
echo "\n------------------------------\n\n";
// get events
$events = $service->events->listEvents($calendarListEntry->id);
foreach ($events->getItems() as $event) {
echo "- " . $event->getSummary() . "\n";
echo "- " . $event->getStart()->getDateTime() . "\n\n";
}
}
$pageToken = $calendarList->getNextPageToken();
if ($pageToken) {
$optParams = array('pageToken' => $pageToken);
$calendarList = $service->calendarList->listCalendarList($optParams);
} else {
echo "break";
break;
}
}
echo "calendar summary: " . $calendarListEntry->getSummary();
echo "\ncalendar id: " . $calendarListEntry->getId();
echo "\n------------------------------\n\n";
Obviously the $calendarList and $calendarListEntry is empty....