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

Running samples throws invalid_request error when getting oauth token #587

Closed
hmbrg opened this issue May 27, 2016 · 4 comments
Closed

Running samples throws invalid_request error when getting oauth token #587

hmbrg opened this issue May 27, 2016 · 4 comments
Assignees

Comments

@hmbrg
Copy link

hmbrg commented May 27, 2016

Hi, so when just running the YouTube search.js sample the auth process seems to work fine until I'm doing an actual request to the YouTube Data API:

Error getting oAuth tokens: Error: invalid_request
D:\Stuffy\google-api-nodejs-client\node_modules\google-auth-library\lib\auth\oauth2client.js:270
  if (!thisCreds.access_token && !thisCreds.refresh_token) {
                ^

TypeError: Cannot read property 'access_token' of null
    at OAuth2Client.getRequestMetadata (D:\Stuffy\google-api-nodejs-client\node_modules\google-auth-library\lib\auth\oauth2client.js:270:17)

That happens with every example, didn't change any of the code except the credentials.

Thanks!

@jmdobry jmdobry self-assigned this Jun 9, 2016
@jmdobry
Copy link
Contributor

jmdobry commented Jun 9, 2016

@brighthero Did you add your settings to google-api-nodejs-client/samples/secrets.json before running the example?

@sosloow
Copy link

sosloow commented Jul 28, 2016

Hi, I have the same problem when running samples.

  1. I set client_id and client_secret in secrets.json
  2. printed self.authorizeUrl with console.log
  3. opened url in browser
  4. google redirects me to http://localhost:8080/callback?code= . The page says, everything is ok
  5. script throws Error getting oAuth tokens: Error: invalid_request

@sosloow
Copy link

sosloow commented Jul 28, 2016

Oh, I got it. The callback url gets called twice for some reason (by google or something), and the second time it is called without authorization code. Script tries to get credentials without the code and crushes.
So the solution for me was to check qs.code in the request.
And, btw, spawn('open') does nothing on my machine, so I had to output the link to the console.

I'd sent a pr, but there are some License Agreements and stuff...

@JustinBeckwith
Copy link
Contributor

Greetings folks! We've done a fair bit of work here, and the samples should all be working well with the new auth client. We've moved away from spawn to the opn module which should work on multiple operating systems too :) If you're still having issues, let us know!

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

4 participants