我正在使用 google/apiclient 开发 Yii2。 我不断收到“错误:redirect_uri_mismatch”
- 我已将“http://localhost ”设置为授权重定向
- 尝试过“https://localhost”
- 尝试过“https://localhost/”
- 等待超过 1 小时以使更改生效
似乎没有任何作用,有什么见解吗?
我的代码没什么特别的:
$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('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0adb99fada1a9ac80aeafb4eeb2a5aca5b6a1aeb4" rel="noreferrer noopener nofollow">[email protected]</a>');
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();
}
根据错误,请求似乎正常:
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
最佳答案
您需要在 Google API 控制台中注册您的 API 端点:
Please note that the exact (absolute) route you're using needs to be registered
这个问题已经在这里得到了回答,我相信您也可以在这里找到答案:Google OAuth 2 authorization - Error: redirect_uri_mismatch
关于php - OAuth 是否允许 localhost 进行调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58294077/