DEV Community

Discussion on: Google Calendar integration with NodeJS without OAuth 2.0

Collapse
 
jdunk profile image
jdunk

First: this article was super helpful and got me 95% of the way to a working solution. So thank you so much for posting it!

Here's what didn't work for me:

When I ran the posted code, I would get this error:

The API returned an error: TypeError: authClient.request is not a function
Enter fullscreen mode Exit fullscreen mode

...which, after googling it, seems like an auth or API version error.

It could be related (or not) to the fact that I am not using a G-Suite account. So for anyone wondering how to make it work for a regular google account, here's how!

What I did is I replaced this:

const client = google.auth.getClient({
  credentials,
  scopes,
})
Enter fullscreen mode Exit fullscreen mode

...with this:

const client = new google.auth.GoogleAuth({
  keyFile: '<CREDENTIALS_FILE>.json',
  scopes,
})
Enter fullscreen mode Exit fullscreen mode

(Source: googleapis.dev/nodejs/googleapis/l...)

So in my case, there was no need to require() the credentials file (as google.auth.GoogleAuth() does that for us), so I removed this line:

const credentials = require('<CREDENTIALS_FILE>.json')
Enter fullscreen mode Exit fullscreen mode

...and I also removed this line:

client.subject = '<SERVICE_ACCOUNT_EMAIL>'
Enter fullscreen mode Exit fullscreen mode

...as the service account email already exists in the credentials file (under the "client_email" key).

So the end-result is even more simple, thanks to google.auth.GoogleAuth().

And it might work for G-Suite accounts too. (So if anyone with a G-Suite account wants to try this, please post here to let us know if this worked for you too.)

Collapse
 
balindersingh profile image
Balinder Singh

Got the same issue. this change fixed the issue. Awesome tip.