Google calendar API and node js - googleAuth problem is not a constructor

I am trying to configure the Google Calendar API on Node using Node.js quick start which is displayed here

After completing all the first three steps and running my quickstart.js to check if it works (which I copied and pasted using quick launch), I get the following error:

"TypeError: googlAuth is not a constructor", it refers to this line of code:

var auth = new googleAuth(); 

googleAuth is declared as follows:

 var googleAuth = require('google-auth-library'); 

I could not find any solution on the Internet.

the full code is located at the link above in the third step. Thanks in advance, Assaf.

+5
source share
3 answers

I think this is basically a problem with installing the nodejs and google library. I am running node v8.2.1 on my system and I can execute quickstart nodejs correctly. Try installing the latest nodejs nodes and run these lines again.

 npm install googleapis --save npm install google-auth-library@0. * --save 
+2
source

The version has changed, as the answers say here. According to the new docs , you should require the package as follows:

 const gal = require('google-auth-library'); const auth = new gal.GoogleAuth(); const jwtClient = new gal.JWT(); const oAuth2Client = new gal.OAuth2Client(); ... // if you're using Node 6+, you might find this convenient: const {GoogleAuth, JWT, OAuth2Client} = require('google-auth-library'); 

The old way was this:

 var GoogleAuth = require('google-auth-library'); var auth = new GoogleAuth(); var jwtClient = new auth.JWT(); var oAuth2Client = new auth.OAuth2(); 

Basically the way GoogleAuth links have GoogleAuth . Now this is one part of the whole package, not the main export.

This change worked for me!

+2
source

Google recently released version 1.0.0 . If you installed without the npm version, you installed the latest version. In this case, your code should be:

 const {GoogleAuth} = require('google-auth-library'); const auth = new GoogleAuth(); 
0
source

Source: https://habr.com/ru/post/1274683/


All Articles