Home > database >  How can I programmatically seamlessly share a clients google calendar with a service account as auto
How can I programmatically seamlessly share a clients google calendar with a service account as auto

Time:08-24

I am trying to share a service account with any user's calendar and would like to know if anyone knows how to do so on the backend which is node.js or the frontend which is flutter/dart so that the user has to do as little as possible to add the service account to their calendar.

When onboarding a user on the flutter/dart front end I would like to ask a user if a service account can be added to a calendar on their account so the system can handle certain scheduling tasks for the user. I am assuming that the user is not technical. Ideally, I would like to add a new calendar to the user's account and share the service account with that.

After onboarding I would like all actions which the system does with the users calendar to take place on a node.js server using the service account.

I would like the service account to be able to read events from the user's calendar, add events, and find times during which the user is not already booked.

I have searched the internet for many hours and there is very little information about how to do this.

Also, will using a service account to view and modify and find available times on a user's calendar only work with workplace calendars and not with free calendars?

CodePudding user response:

There are services/methods available using Calendar API that can achieve the functionality you want, you may look into the following:

  • Method: users.list - for listing the users within your organization (as reference calendarId for the other methods needed)
  • Calendars:insert - for creating a secondary calendar.
  • Acl: update - for setting Access Control List to the created secondary calendar.
  • Events: list & Events: get - for listing and getting the specified event needed for modification.

Now, for creating and authorizing the service account for this, you may check this reference link for Authorizing Requests to the Google Calendar API.

Bear in mind that read/write access to events/calendars requires the correct scope as define on the link above.

Here's the OAuth 2.0 scope information for the Google Calendar API:

https://www.googleapis.com/auth/calendar read/write access to Calendars https://www.googleapis.com/auth/calendar.readonly read-only access to Calendars https://www.googleapis.com/auth/calendar.events read/write access to Events https://www.googleapis.com/auth/calendar.events.readonly read-only access to Events https://www.googleapis.com/auth/calendar.settings.readonly read-only access to Settings https://www.googleapis.com/auth/calendar.addons.execute run as a Calendar add-on

And lastly, service accounts have no rights/authorization to access personal Gmail accounts, since the Domain-wide delegation feature only applies to user accounts within your organization.

  • Related