Google Calendar API with PHP and a Service Account won't work anymore

one text

Solution:

step one.

I would like you to check that the issue isnt simply that the calendar you are looking for is not appearing in your calendarlist, it is correct that service accounts no longer insert automatically into the calendar list but that does not mean that you dont have access to the calendar.

Try and do something like this to add the calendar to calendarlist. You should be able to find the calendar id from Google calendar web application.

$calendarListEntry = new Google_Service_Calendar_CalendarListEntry();
$calendarListEntry->setId("calendarId");

$createdCalendarListEntry = $service->calendarList->insert($calendarListEntry);

echo $createdCalendarListEntry->getSummary();

option two

If as you say that you truly do not have access to the calendar anymore and the issue isn't simply that it wasn't added automatically for you to the calendar list.

The only work around for this would be to create a dummy Google user, then using Oauth2 authenticate the user using Offline access, this will give you a refresh token.

You can then use the refresh token to request a new access token when ever you need to. Using

$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());

This is not an ideal solution as refresh tokens can stop working although it is extremely rare it can happen so you will need to baby sit the code and have it notify you if it has any issues with its refresh token so that you can create a new one

Source