2
votes

Initial situation:

  • In one of our services, we use a service account to call Google Calendar API.
  • User can share their calendars with this technical account via its technical emailaddress (@.iam.gserviceaccount.com).
  • As calendars are shared, we can query them via API (CalendarList/List: https://developers.google.com/calendar/v3/reference/calendarList/list)
  • All this was working fine for several years without problem.

Current issue:

  • As we have discovered recently, newly shared calendars are not returned via the API call anymore. Calendars shared in the past are still returned (!)
  • We are aware of pageTokens and handle them - this couldn't be a problem. In case of one (test) account only 8 calendars are shared currently and we cannot get more.
  • There is no error/warning during the call on backend side
  • There is no error/warning/quota problem on the Google Developer Console

We haven't received any warning/alert from Google about Calendar API changes or limitations of our account(s). Also I haven't found any publicly known issue/outage about Google Calendar.

What could be the problem?

Should I report it to Google? If yes how exactly? All I could found was a "Google Cloud Platform Free Trial Troubleshooter", where (apart from a suggest to use stackoverflow ;]) all I can do with a "specific question and technical support" is to "start a chat", which leads to an internal Google site (moma). Is there anything else I could try?

Any help would be much appreciated!

UPDATE: There as indirect trace/hint in official documents that Google has changed this behaviour of (automatically) accepting shared Calendars - compare the "Share an existing calendar" section's current and 2019 august version:

UPDATE 2 I have managed to report this issue to Google thanks to @DaImTo (google account required): https://issuetracker.google.com/issues/148804709

The point is the following:

  • "Due to a recent change of behaviour, any account has to explicitly "accept" a Calendar that has been shared with them."
  • Status: Won't Fix (Intended behavior)
3
Please certify this statement "As we have discovered recently, newly shared calendars are not returned via the API call anymore. Calendars shared in the past are still returned " Please explain exactly what your problem is as it is written currently its hard to understand your issue.DaImTo
All right, I try to articulate more clearly. Steps to reproduce: 1. User shares his/hers calendar with the email of the service account 2. Executing CalendarList/List, we expect to return all calendars, including the one shared in step 1 Situation is, that the API call returns only "earlier shared" calendars, but not the one we share now. I hope I clarified the bits - if not, please ask specific questions, thank you!gabowsky

3 Answers

5
votes

There has been a recent change

After you share a calendar with a user / a service account, this user / service account has to "accept" the sharing by adding the shared calendar to his calendar list.

This can either be done (in case of a user) from the UI by clicking "Add this calendar" or programmatically (works both for users and service accounts) with the method CalendarList: insert.

2
votes

One more solution to this is

1) Add Calendar to your Google Account

2) Share Calendar with Service Account Email Id

3) Go to settings and Sharing in newly created calendar and find the Calendar Id

4) Follow this Link - https://developers.google.com/calendar/v3/reference/calendarList/insert

This is sample PHP Code for adding existing calendar in Service Account

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

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

echo $createdCalendarListEntry->getSummary();

5) Now call Calendar List API and you will find added calendar id in service account calendar List

1
votes

CalendarList.List Returns the calendars on the user's calendar list.

This is not necessarily all of the calendars a user has access to. A users calendar list appears on the bottom left hand side of the google calendar web app

enter image description here

When a user is granted access to a new calendar they accept access via an email. When they do that the calendar is normally added to their calendarlist.list. This does not happen with a service account because it doesn't have the ability to check an email and accept the invite it just has access.

If you want the calendars added to the service accounts calendarlist then you will need to insert them via the service account. using calendarlist.insert

Im not sure why you think this worked in that past i have been using this api for years and never bothered with using the calenadarlist with service accounts for this very reason.

  1. User shares his/hers calendar with the email of the service account 2. Executing CalendarList/List, we expect to return all calendars, including the one shared in step 1 Situation is, that the API call returns only "earlier shared" calendars, but not the one we share now. I hope I clarified the bits - if not, please ask specific questions, thank you!

There is no method that will return all calendars that a user has access to. TBH the response would be huge consider all of the public calendars out there in the wild they would also be returned.

Tip for using service accounts.

service accounts are not intended for you to be giving out to users to have them grant it access to their calendars. Service accounts are meant for you the developer to have a static calendar that you can use in your application and save data to that.

If you are accessing a users calendar then you should be using Oauth2 and saving the refresh token if you need access to their data when they are offline.

Report issue

There have been a lot of changes recently around service accounts and google calendar i have reported servral issues myself over the last few months issue forum I suggest that you submit this as an issue. Link it here and i will see if i can find my contact on that team to ping about the issue.