Avoid 'Invalid Credentials' with Google OAuth2
I was struggling setting up OAuth2 authorisation to Google and the problem was down to the scope
I was requesting.
I requested https://www.googleapis.com/auth/calendar
in order to access the Calendar API on behalf of the user but was receiving
"reason": "authError",
"message": "Invalid Credentials"
Turns out you also have to request the https://www.googleapis.com/auth/userinfo.email
scope as well as the scopes you're interested in. Google returns the email in the credentials hash and thus, I believe, if you haven't requested access to it you can't read it.
Written by Adam Bird
Related protips
5 Responses
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/22356/profile_pic.jpg)
If you are using https://github.com/zquestz/omniauth-google-oauth2 make sure to follow the note in README.
"You must enable the "Contacts API" and "Google+ API" via the Google API console."
This fixed the 'Could not authenticate you from GoogleOauth2 because "Invalid credentials".' problem for me.
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/125523/none.jpg)
Thanks abhishek77in! You saved me lots of trouble.
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/134618/none.jpg)
Thank you! This solved my problem.
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/386992/ian_hardy.png)
Thanks for sharing.
Thanks for sharing this information...