-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use gapi with service account? #854
Comments
To access Google Calendar events using a service account, you'll need to use the Google API Client Library. Below are the steps to achieve this in JavaScript: Set Up Your Google Cloud Project: Create a Service Account: Install the googleapis library using npm:
Write JavaScript Code:
Adjust the calendarId to match the Google Calendar you want to access. The calendar.readonly scope is used for fetching events. Run Your Application: Service Account Permissions: Calendar ID: Replace ./path/to/your/service-account-key.json with the actual path to your downloaded service account JSON key file. By following these steps, you should be able to access Google Calendar events using a service account in your hotel website application. |
const { google } = require('googleapis'); this does not work in my reactjs application. it throws a lot of errors. |
The issue is you are trying to do something that is unsupported. Service accounts are supposed to be used for server to server communication(backends.. in this case 'googleapis' is a nodejs module). Frontend applications can use gapi.client but then they need to use api_key/client_id and OAuth. |
I'm trying to use Google Service account (https://developers.google.com/identity/protocols/oauth2/service-account#java) in my app now that
gapi.client.init
doesn't work anymore but I don't know how to do it with this library.My app is a website for a hotel and I want to show a calendar with the bookings and availability. All the booking events are on the Google Calendar account of the hotel owner so I just want to fetch the events to display them to the user.
I have already created a Service Account credential here: https://console.cloud.google.com/projectselector2/iam-admin/serviceaccounts?supportedpurview=project
The text was updated successfully, but these errors were encountered: