Google API to view any user's calendar list - google-api

I am using Google API to try to view a user's calendar list, mainly the shared calendars a user had access to. But according to the Google Calendar.List api , I can view only the logged user's calendar. So I wanted to ask if there is a way around this.
The use case that I am working on requires removing any shared calendars of a user whose status has been changed to suspended.
Thanks
DS

Related

Separate Google login from Google Calendar API

I have a platform that allows people to sign up/log in with their Google account.
Inside the platform, there is a calendar feature where people can connect their Google Calendar and share the data between our app.
I'd like to know if there's a way to separate google calendar with the normal login stuff, so when they sign up with Google, we won't be asking for their Google Calendar permission. Once they are in the app, if they want to connect their Google Calendar, they can do so by clicking another button.
Currently, the 2 things are linked together and I'd like to separate them.
My app is https://clascity.com/
Any help is greatly appreciated!
Just because you use Google signin (openid connect) does not mean that you have permission to access the users Google calendar data.
Google calendar data is private user data, you need specific permission to access the users calendar data, you cant just let them login without asking for permission to access the data you need to access. The user needs to know what data you will be accessing and accept that specifically though the authorization form that google supplies.
Yes, in fact, what you are suggesting is considered a best practice [1]. Use incremental authorization as described here [2].
[1] https://developers.google.com/identity/protocols/oauth2/policies#unbundled-consent
[2]
https://developers.google.com/identity/sign-in/web/incremental-auth

Get All Calendars in Google Org via Google API

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!
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
unfortunately you cant. 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 where 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 thats not going to work very well with a service account.
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:
Google Calendar API - Domain Resources
Delegating domain-wide authority to the service account

Errors accessing Shared/Room Calendars through Microsoft Graph API

I'm making an application that requires access to the shared/room-resource calendars in an Office 365 instance, using non-admin accounts. I've registered an app (in the Microsoft Application Registration Portal) using the V2 endpoint and Auth Code Grant. This successfully allows me to log in, and gives me a functional token with the Calendars.ReadWrite.Shared scope. With this token, I can retrieve my own calendars, and calendars that have been explicitly shared with me (and therefore added to my list of calendars). All of this is doable with just the normal Calendars.ReadWrite scope.
However, I get errors when requesting access to any other shared calendars, like the room calendars. Here's an example. If I make a GET call to https://graph.microsoft.com/beta/users/my-own-email#business.com/calendars it successfully returns a list of my calendars. If I make a GET call to https://graph.microsoft.com/beta/users/meetingroom1.4#business.com/calendars I get a 404 (Not Found) Error. The same error occurs for any other user, not just meeting rooms. Note that I can see these calendars when I'm logged into Office 365 online with the same account.
A different error occurs if I ask for events not calendars. If I make a GET call to https://graph.microsoft.com/beta/users/meetingroom1.4#business.com/events, I get a 500 (Internal Server) Error.
I've checked all the other threads I can find on the issue, and this one from November How to access shared calendars from Office REST API? says there's some kind of blocking issue on Microsoft's end. It's using the Office REST API rather than Graph, but on the back-end the APIs call the same stuff. Is this issue still about? Alternatively, am I missing some further permissions? I tried adding quite a few different permissions on top of Calendars.ReadWrite.Shared, but none of them fixed it. Is there a correct combination?
Thanks so much for any help, and let me know if any other info would be useful for diagnosis.
So if anyone else happens to be interested in this, I figured out a way to access room resource calendars without using the Calendars.ReadWrite.Shared permission. This allows you to use just the Calendars.ReadWrite permission to access the room resources, by moving them into the list of calendars of the email you're authenticating with. However, it will only work for specific accounts that you share the calendars with, so won't be usable in apps that have to work for any account. This is good enough for my use-case, but may not be for yours.
First, find or make an account that is a delegate to, and has full access to, the room resource calendar you want to use. On that account click 'Open another mailbox' in the dropdown list under your profile image.
Open another mailbox location
In the pop-up that follows, put in the email address of the room resource calendar that you want to use.
Then, on the new page that opens (which should be the Office account of the room resource calendar):
Navigate to the calendar page
Click 'Share'
Share the default calendar with the account you plan to authenticate with.
Then log into that 'authentication' account, check its email for the notification of the shared calendar, and click 'accept'. What this will do is move the calendar into the authenticated account's list of calendars, meaning you can access it with just a call to the https://graph.microsoft.com/v1.0/me/calendars endpoint. You'll have to repeat it for every calendar you want to be able to access, sadly.

Google Calendar API for multiple users:

I am developing a web app in Ruby on Rails for registering talks given in my company. If a user registers for a talk, then it should update the Google Calendar event for all users who have the event on their Google Calendar.
https://developers.google.com/accounts/docs/OAuth2
I need to use OAuth2 since I need to modify the user's data and I need to obtain the consent from the user as well. So I can redirect them to the Authentication page where they can sign in to view their account. But in this case the user data I want to modify is Calendar of all those people who signed up for the event.
Is there any easy way to do this? Like using an admin account?
When you want to update the Google Calendar event for all users who already have event in their calendar, you no need to use OAUTH as user authentication is not required.
This is because, when there is an update in the existing event then all the users (who are all already added as attendee in the existing event) calendar gets updated without users consent screen.

add calendar to another user's calendar list

Not sure if this is possible or if anyone has managed to do this. I have user with super admin access, with which I can create a new user for my domain. However I also want to add a couple of calenders to the created user's calendar list. When I create a user I authenticate using my super admin, but then I can't add a calendar to the user's calendar list since I am not logged in as the user. Is it possible to do this as the super admin, or do I have to logout and authenticate as the created user in order to add calendars to their list? This is the base url to which the post request is made:
https://www.googleapis.com/calendar/v3/users/me/calendarList
in the place of me could I pass in the id of the user? I couldn't find any parameter in the documentation with which I can specify the user to whose list I want to add a calender.
Thanks
Two options:
Each user much login to google calendar and share thier calendar to a single user. You can then use this account to update their calendars. Note that google has limitations to how many calendars and request you are allowed before the account goes to read-only mode.
Buy a google apps domain (5$per user per month) and create a service account at console.developers.google.com. Create a project and give it domain wide delgation at admin.google.com. In Apps engine you should be able to give access for admin to modify all users calendars.
No matter what case you choose, you also need to enable CalendarAPI at dev console site. Now with private key created from website request OAuth2 access token, where sub field is set for the users that you want to change calendar for. With returned access token use CalendarAPI to modify calendar.
Sry for bad english and short description, i'm in a hurry. /conner ;)

Resources