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

Error: Request to googleapis.com/oauth2/v4/token Failed When Using Google Spreadsheet npm Package with VPN in China (Works Fine in Morocco) #684

Open
Adoo2401 opened this issue Mar 23, 2024 · 1 comment

Comments

@Adoo2401
Copy link

I'm currently working on a project where I need to access Google Sheets using the google-spreadsheet npm package. Due to restrictions, I'm based in China and using a VPN to access Google services. However, I'm encountering an issue where I'm getting the following error
Error: Request to https://www.googleapis.com/oauth2/v4/token failed, reason:

Here's the relevant code snippet:
`import { JWT } from "google-auth-library";
import { GoogleSpreadsheet} from "google-spreadsheet";

const serviceAccountAuth = new JWT({
email: creds.client_email,
key: creds.private_key,
scopes: SCOPES,
});

const doc = new GoogleSpreadsheet(googleSheetId, serviceAccountAuth);`

I suspect this error is due to the VPN and possibly related to Google's restrictions in China. How can I resolve this issue and successfully authenticate with Google's OAuth2 service while using a VPN in China? Any insights or workaround suggestions would be greatly appreciated. Thank you!

Note: I've tested this code with a friend located in Morocco, and it works fine on their laptop without any issues.

@theoephraim
Copy link
Owner

Sorry but that’s really outside the scope of this project…

But it sounds like you need to route the google requests through a proxy. This is very common in scraping applications so just search for things related to scraping, proxies, and changing countries.

Internally this tool uses axios, so I think after initializing the document, you should be able to access the axios instance and mess with the settings to inject proxy behaviour.

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

2 participants