php - OAuth 是否允许 localhost 进行调试?

标签 php google-api google-oauth google-api-php-client google-developers-console

我正在使用 google/apiclient 开发 Yii2。 我不断收到“错误:redirect_uri_mismatch”

似乎没有任何作用,有什么见解吗?

我的代码没什么特别的:

$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

See a capture of my google config

最佳答案

您需要在 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/

相关文章:

php - 无法运行具有代码覆盖率的 Codeception 测试

google-api - 如何在 Google Ngrams 中搜索 "dated"单词和短语?

ios - 针对 Google 帐户关联的操作

c# - 从重定向的 URI 接收 Oauth2 授权代码

http - 为什么 google oauth2 playground 无法返回数据?

php - 在 PHP 中将 MySQL 数据导出到 Excel

php - 如何在android中以图形形式表示mysql数据库?

PHP:允许用户更改背景颜色不起作用?

google-api - JavaScript 错误 - 日志 :Net state changed from BUSY to CLIENT_ERROR

google-apps-script - 使用 gspread 写入时出现 Google Sheets API 权限错误