Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'OAuth2' of undefined #6

Closed
IshaanRawat opened this issue Apr 5, 2018 · 9 comments
Closed

Cannot read property 'OAuth2' of undefined #6

IshaanRawat opened this issue Apr 5, 2018 · 9 comments

Comments

@IshaanRawat
Copy link
Contributor

In the Google sheets api sample code:
https://github.com/gsuitedevs/node-samples/blob/e426bd6af84904ea49ebd043787659936264727a/sheets/quickstart/index.js#L20

Expected Behavior

The following should be working properly.
const google = require('googleapis');
const OAuth2Client = google.auth.OAuth2;

Actual Behavior

Instead, it is showing
Cannot read property 'OAuth2' of undefined

Steps to Reproduce the Problem

  1. Just create a quickstart.js with the code linked above.
  2. Install required packages.
  3. Run node quickstart.js.

Solution

After debugging the code, I found out that it is using the google property in the google variable that we required from googleapis. This bug was resulting in the undefined behavior as google.auth is not defined. What actually defined is google.google.auth.
So what I did was extract the google property directly be using ES6 destructuring which fixed this issue and all the further issues which were created by it.
const {google} = require('googleapis');

Specifications

  • Node version - v8.10.0
  • OS - Linux(Ubuntu v16.04)
@iwin2471
Copy link
Contributor

iwin2471 commented Apr 13, 2018

I already fix this problem at #3
but I didn't mention about this problem in my description sorry

@IshaanRawat
Copy link
Contributor Author

No worries. 👍
By the way, this problem is still there in many gsuitedev/node-samples quickstart codes and READMEs. If you want I can fix them on all the places.

@grant
Copy link
Contributor

grant commented Apr 13, 2018

@IshaanRawat Please do! PRs are very welcome and much appreciated.

@IshaanRawat
Copy link
Contributor Author

@grant I found this issue on many of the Node.js documentation on the Google website also. I would be happy to contribute to those also.

@paigekehoe
Copy link

This change isn't reflected on the sheets page of developers.google.com still!
See: https://developers.google.com/sheets/api/quickstart/nodejs
Not sure if this is the spot to raise this though. Let me know if I should post somewhere else.

@grant grant reopened this May 1, 2018
@grant
Copy link
Contributor

grant commented May 1, 2018

Thanks @paigekehoe.
Looks like I haven't published the updated GitHub snippets for all the pages with changes in the above PR.
I will leave this issue open until I do.

@kielypatrick
Copy link

Thanks, good spot!

@awesome-urch
Copy link

@IshaanRawat Thanks!

@grant
Copy link
Contributor

grant commented May 12, 2018

Published.

@grant grant closed this as completed May 12, 2018
synox added a commit to synox/quizlet-sheet-sync that referenced this issue May 18, 2018
synox added a commit to synox/quizlet-sheet-sync that referenced this issue May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants