Search code examples
javascriptphplaravelgoogle-calendar-api

Google Calendar API per user gmail account


Currently I have this code to fetch all dates from my google calendar

https://developers.google.com/calendar/api/quickstart/js

As you can notice, there is client id & client secret key on js code.

I gathered it on my example-main-email@gmail.com

Code this will prompt something like this

enter image description here enter image description here

So I used example-main-email@gmail.com to login & authorize

As you can see, it lists down all dates from google calendar under example-main-email@gmail.com

enter image description here

But my question is,

Is it possible to fetch calendar dates from different gmail account.

For example, I have 3 users

1st-example-main-email@gmail.com - If I authorize this email, it will fetch calendar dates under this account

2nd-example-main-email@gmail.com - If I authorize this email, it will fetch calendar dates under this account

3rd-example-main-email@gmail.com - If I authorize this email, it will fetch calendar dates under this account

So basically to fetch calendar dates based on gmail account

I'm planning to implement this type of functionality on my laravel project. I just want to know if this case is possible


Solution

  • Yes, this is doable, as long as the account owners provide your application with authorization to do so (either via OAuth token or a client secret)

    In case you are referring to a set of Google Workspace Accounts, (and you want to automate it, this will require for you to use a Service Account + enable Domain Wide Delegation for it) plus having your application set to internal, this way it will not require for you to go through an application audit. Your client secret will work for any of these types of accounts inside your domain.

    On the other hand, If you are referring to Gmail.com accounts you can use the ‘Test Users’ feature and add those other Gmail accounts there. Be mindful of the limitations though. In this option, your client secret will not work, you will need to change to an OAuth authentication process.