0

Following this guide to manipulate google spreadsheets - http://voidcanvas.com/node-js-googleapis-v4-spreadsheet/ I have been getting "googleAuth is not a constructor" error.

Searching the web I found that the new version of google-auth-library has a problem with the old syntax. Installing the 0.12.0 version has gotten me into the "authorize App by visiting this URL:" section but the provided URL is a broken link that says:

Error: invalid_request Invalid parameter value for redirect_uri: Invalid scheme: urn:ietf:wg:oauth:2.0:oob

on the other hand trying to stay with the current(updated) version of the google-auth-library I found a fix that says to change these lines

let oauth = require('google-auth-library');
...
var oauth2Client = new oauth.OAuth2(clientId, clientSecret, redirectUrl);

but it created an "oauth.OAuth2 is not a constructor" error.

This is the original code that runs at 0.12.0 and returns a faulty URL.

let fs = require('fs');
let readline = require('readline');
let googleAuth = require('google-auth-library');
...
authorize(credentials) {
var clientSecret = credentials.installed.client_secret;
var clientId = credentials.installed.client_id;
var redirectUrl = credentials.installed.redirect_uris[0];
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);

This is the code that runs at the updated version + the fix

 let fs = require('fs');
 let readline = require('readline');
 let oauth = require('google-auth-library'); 
 ...
 authorize(credentials) {
 var clientSecret = credentials.installed.client_secret;
 var clientId = credentials.installed.client_id;
 var redirectUrl = credentials.installed.redirect_uris[0];
 ///var auth = new googleAuth();
 var oauth2Client = new oauth.OAuth2(clientId, clientSecret, redirectUrl);

I expect the outcome to be a good URL that returns the code i need to complete the authorization and in turn updates my sheet.

segev
  • 43
  • 6

1 Answers1

0

For newer versions, you need to use the OAuth2Client property which you can get with destructuring. Other common properties are auth or JWT:

const {OAuth2Client} = require('google-auth-library');

See also https://www.npmjs.com/package/google-auth-library

user835611
  • 2,309
  • 2
  • 21
  • 29