I'm working on Yii2, using google/apiclient. I keep getting "Error: redirect_uri_mismatch"
- I've set "http://localhost" as authorized redirects
- Tried with "https://localhost"
- Tried with "https://localhost/"
- Waited more than 1hr for changes to take effect
Nothing seems to work, any insights?
My code is nothing special:
$session = Yii::$app->session;
$gClient = new Google_Client();
$pathToSecret = Yii::getAlias('@app/auth/gCalendar_ClientSecret.json');
$gClient->setAuthConfig($pathToSecret);
$gClient->addScope(Google_Service_Calendar::CALENDAR_EVENTS_READONLY);
$gClient->setLoginHint('my_mail@not.relevant');
if ($session->has('oauth_access_token')) {
$gClient->setAccessToken($session->get('oauth_calendar_access_token'));
//do something else
} else {
$redirectUri = Url::toRoute('/calendar/oauth-response', 'http');
$gClient->setRedirectUri($redirectUri);
return $gClient->createAuthUrl();
}
Based on the error, the request seems fine:
The redirect URI in the request, http://localhost/ascoSL/public_html/sl/index.php?r=calendar%2Foauth- response, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/XXXXX