Get All Calendars in Google Org via Google API
Asked Answered
A

3

6

Goal: I'm trying to get all the calendars in my Gsuite org.

Problem: I know I can get a list of calendars using CalendarList.list but that's only if the user or service account has all the calendars in its list and even then it's not always accurate because the calendars don't always get added to the service account's calendar list and a user could potentially remove the calendar from their list.

Question: Is there a way to just grab every calendar in my Google org? Let's say my domain is @someorg.com. I want every user's calendar as well as calendars created through the api. I was thinking this might be possible with the GSuite Admin SDK, but I haven't been able to find anything that allows me to do this. It only handles Resources.calendars which is different than a Calendar object.

Any help appreciated! Thanks!

Algetic answered 6/12, 2019 at 0:32 Comment(3)
This might be better in the webapps forum. Take a look over there for posts that are similar. webapps.stackexchange.com/questions/39296/…Vincenzovincible
Thanks for the suggestion, but no luck :\ Also, I'm looking for a solution using the Google API, not the app.Algetic
@Vincenzovincible this is a programming question not a GSuite web application question. Web apps wont be able to help getting the information back with a service accountEarldom
E
2

Unfortunately you can't. The only way to get a list of calendars that the user has access to is though the calendarlist.list method. The issue with this is that you must be sure that all of the users' calendars were actually added to calendarlist which is not always the case.

What you can do is prompt the user asking them to share with you any other calendars but that's not going to work very well with a service account.

Earldom answered 6/12, 2019 at 8:16 Comment(1)
Marking this correct. Ended up just doing this manually. Like DalmTo mentions above, it's not possible to get all calendars including service account created calendars.Algetic
M
5

You need to use the service account to get a token for each user, for this you need each user's email which you can get making a Users.list request [1]. With each token you can do a CalendarList.list request [2] for each impersonated user which will retrieve you the user's calendars it's subscribed to.

You can filter the results to get the calendars with the accessRole [3] field set to owner, if you want the calendars created by the user. You could get the deleted calendars as well by setting the showDeleted parameter to true [2].

[1] https://developers.google.com/admin-sdk/directory/v1/reference/users/list

[2] https://developers.google.com/calendar/v3/reference/calendarList/list

[3] https://developers.google.com/calendar/v3/reference/calendarList

Moshe answered 6/12, 2019 at 14:38 Comment(4)
This is actually a pretty good idea :) Do you know if [1] will also return service account user emails? Besides the actual user calendars, I also have calendars created by a service account that belong to the service account as well. Thanks!Algetic
No sorry I don't know, you could test it and see. If not, you could do a workaround giving access to the the service account calendars to a single user and retrieve those calendars through that user, and may be filter by one of the calendar fieldsMoshe
If it helped you, please consider accepting the answerMoshe
@AndresDuarte I see you have 3 footnotes but none of the footnote references mention #3. Should one point to it in the answer?Vincenzovincible
E
2

Unfortunately you can't. The only way to get a list of calendars that the user has access to is though the calendarlist.list method. The issue with this is that you must be sure that all of the users' calendars were actually added to calendarlist which is not always the case.

What you can do is prompt the user asking them to share with you any other calendars but that's not going to work very well with a service account.

Earldom answered 6/12, 2019 at 8:16 Comment(1)
Marking this correct. Ended up just doing this manually. Like DalmTo mentions above, it's not possible to get all calendars including service account created calendars.Algetic
I
0

Considering the official documentation provided by Workspace(formerly G-Suite), this can be achieved by using service accounts with domain-wide authority delegation.

Please check the documentations below:

Isoelectronic answered 21/9, 2022 at 14:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.