As little as having a '/' at the end of your uri and not having the same '/' at the end in your code will throw it off.
Your site URL
and the Authorized redirect URIs
in developer console should be the exact match.
This kind of error occurs if one URL has www
(http://www.example.com
) and the other URL is non-www
(http://example.com
).
Other common URI mismatch are:
- Using
http://
in Authorized Redirect URIs and https://
as actual URL, or vice-versa
- Using trailing slash (
http://example.com/
) in Authorized Redirect URIs and not using trailing slash (http://example.com
) as actual URL, or vice-versa
Here is the step-by-step procedure (with screenshots) to update the Authorized redirect URIs in Google Developer Console (For those like me who found it difficult to get to that page).
Go to https://console.developers.google.com
Select your Project
![](https://www.manongdao.com/static/images/pcload.jpg)
- Click on the menu icon
![](https://www.manongdao.com/static/images/pcload.jpg)
- Click on
API Manager
menu
![](https://www.manongdao.com/static/images/pcload.jpg)
- Click on
Credentials
menu. And under OAuth 2.0 Client IDs
, you will find your client name. In my case, it is Web Client 1
. Click on it and a popup will appear where you can edit Authorized Javascript Origin and Authorized redirect URIs.
![](https://www.manongdao.com/static/images/pcload.jpg)
Here is a Google article on creating project and client ID.
It should be a exact match what you have given in the console.developers.com.
In my case I missed the www in the url.
For eg: you have given http://www.google.com but in console.developers.com you gave http://google.com
It will still throw error. So it should be exact match.
The redirect URI (where the OAuth response is returned to) has to be registered in Google APIs console, and the error is indicating that you haven't done that, or haven't done it correctly.
Go to the console for your project and look under API Access. You should see your client ID & secret there, along with a list of redirect URIs. If the URI you want isn't listed, click edit settings and add the URI to the list.
I kept getting this same error until I realized that I needed to put "signin-google" at the end of the redirect setting in the Google API console, like this (ie, NOT http://www.example.org/api):
http://www.example.org/api/signin-google
Please make sure that in your google-client-api, the value of credentials in these field are matched as what you got from Google API console:
$client->setClientId('xxx.apps.googleusercontent.com');
$client->setClientSecret('xxx');
$client->setRedirectUri('http://example.com/oauth2callback');
$client->setDeveloperKey('xx');
This could happen when the value of setRedirectUri is different from the one you set in Google API console.