-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Login Required message when using the googleapis client, but not when trying it manually #1523
Comments
Greetings! The problem may be this line: const drive = google.drive({ version: 'v3', oauth2Client }); That should be: const drive = google.drive({ version: 'v3', auth: oauth2Client }); Hope this helps! |
Wow.... sigh. You are 100% correct! May I buy you a drink? :) |
Amazing |
I've had the exact same odd issue following outdated documentation. If anybody is up for it, you can PR the improper instance creation here https://github.com/gsuitedevs/node-samples/blob/master/classroom/quickstart/index.js#L92 It should use the |
OK, I've reported it. Thanks! |
Was just caught by this documentation issue myself here at the end of 2021. |
finally!, had been trying to fix this issue for a week due to the wrong documentation. |
chatGPT does this mistake |
Environment details
googleapis
version: 36.0.0Steps to reproduce
I'm using the googleapis npm as a Google API client in NodeJS.
Background:
A part of the app that runs separately obtains a user's OAuth access_token and refresh_token and stores it for the rest of the app to use later.
The code that I'm having issues with does the following:
It creates an oauth2Client, based on the docs:
Then it sets the drive object, as per the docs:
const drive = google.drive({ version: 'v3', oauth2Client });
Then, if I make a call to ANY endpoint, I get a 401 Error "Login Required".
Example usage:
I verified that both the code that obtains the tokens and this code are using the same client_id and client_secret.
Here is the fun part. As part of the debugging process, I put in a manual request to the same endpoint:
https://www.googleapis.com/drive/v3/about?fields=user
in the code, using the access_token for the Authorization header, and it WORKED.This code actually returns a valid response.
There seems to be some sort of bug with the googleapis library having to do with authentication being set/being sent to endpoints.
I've tried calling some of the other endpoints down the line in my app manually instead of with the googleapis client and they work (no Login Required error).
The text was updated successfully, but these errors were encountered: