I
I
Igor2018-04-15 14:07:50
Node.js
Igor, 2018-04-15 14:07:50

Problem with Node.js Quickstart. Cannot read property 'OAuth2' of undefined. How to decide?

I do everything according to the instructions https://developers.google.com/sheets/api/quickstar...
when calling quickstart.js it gives an error:
C:\Users\Admin\quickstart.js:4
const OAuth2Client = google.auth.OAuth2 ;
____________________________________^
TypeError: Cannot read property 'OAuth2' of undefined
at Object. (C:\Users\Admin\quickstart.js:4:34)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module. load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10 )
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Shatokhin, 2018-04-15
@aif88

Because the structure of googleapis has changed a bit. It will be right:

const google = require('googleapis').google;
const OAuth2 = google.auth.OAuth;

Always read the current version of the official documentation.
ps and do not forget to specify the software version in the question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question