sbaden
sbaden

Reputation: 565

Google sheets API JavaScript: Access sheet with auth

I'm able to access a public google sheet from within my react app but am now trying access the sheet with credentials. I found a tutorial that walks me thru setting up credentials but the code isn't working for me.

const {google} = require('googleapis');
const keys = require('./interstitials-key.json');

const client = new google.auth.JWT(
  keys.client_email,
  null,
  key.private_key,
  ['https://www.googleapis.com/auth/spreadsheets']
);

client.authorize(function(err, tokens){
  if(err){
    console.log(err);
    return;
  }
  else{
    console.log('connected');
  }
});

I'm getting this error:

"TypeError: Expected input to be a Function or Object, got undefined"

Upvotes: 0

Views: 398

Answers (1)

yuri
yuri

Reputation: 3400

This is a known issue, you'll find reference over here:

https://github.com/googleapis/google-api-nodejs-client/issues/1614

I've reproduced it, certainly it's not fixed, you'll face this error as soon as you call the library

const {google} = require('googleapis');

Some of the resources used on the library are not available on the client side, so, it's not possible to call it from the React side, so you either use it on the server side or you have to use the google javascript client api.

Upvotes: 1

Related Questions