Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to set up Google calendar API on Node, using the Node.js quick start that appear here

After following all the first 3 steps and running my quickstart.js to check if it works (which i copied and pasted from the quickstart) , i get the following error:

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

  var auth = new googleAuth();

googleAuth is declared like that:

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

i couldnt find any solution online.

the full code is on the link above on the third step. thanks in advance, Assaf.

like image 840
Assaff Avatar asked Jan 13 '18 18:01

Assaff


4 Answers

The version has changed like answers here say. According to the new docs, you must require the package like this:

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 used to be like this:

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

Basically what changed is the way to reference GoogleAuth. It is now one part of the entire package instead of being the main export.

This change worked for me!

like image 159
Antonio Cucciniello Avatar answered Nov 02 '22 20:11

Antonio Cucciniello


I think this is mostly a nodejs and google library installation problem. I'm running node v8.2.1 on my system and I'm able to execute the nodejs quickstart properly. Try installing latest nodejs and execute these lines again.

npm install googleapis --save
npm install google-auth-library@0.* --save
like image 31
noogui Avatar answered Oct 07 '22 17:10

noogui


I think this is mostly a nodejs and google library installation problem. I'm running node v8.2.1 on my system and I'm able to execute the nodejs quickstart properly. Try installing latest nodejs and execute these lines again.

npm install googleapis --save
npm install google-auth-library@0.* --save
like image 2
ReyAnthonyRenacia Avatar answered Nov 02 '22 21:11

ReyAnthonyRenacia


Google recently released version 1.0.0. If you installed without a version npm would have installed the latest. In that case your code should be:

const {GoogleAuth} = require('google-auth-library');
const auth = new GoogleAuth();
like image 1
jcragun Avatar answered Nov 02 '22 22:11

jcragun