【问题标题】:redirect_uri_mismatch error when enabling server side access to Google API启用对 Google API 的服务器端访问时出现 redirect_uri_mismatch 错误
【发布时间】:2018-03-15 07:40:25
【问题描述】:

我有一个带有 python 服务器的 android 应用程序。我需要服务器能够不断访问用户的电子邮件,所以我正在遵循本指南:

https://developers.google.com/identity/sign-in/android/offline-access

def google_api(auth_token):
    # If this request does not have X-Requested-With header, this could be a CSRF
    #if not request.headers.get('X-Requested-With'):
        #abort(403)

    # Set path to the Web application client_secret_*.json file you downloaded from the
    # Google API Console: https://console.developers.google.com/apis/credentials
    CLIENT_SECRET_FILE = 'secret.json'

    # Exchange auth code for access token, refresh token, and ID token
    credentials = client.credentials_from_clientsecrets_and_code(
        CLIENT_SECRET_FILE,
        ['https://www.googleapis.com/auth/gmail.readonly', 'profile', 'email'],
        auth_token)

    print credentials
    return credentials.id_token

我收到以下错误: FlowExchangeError:redirect_uri_mismatch

这里是 secret.json:

{"web":{"client_id":"REDACTED",
"project_id":"REDACTED",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"REDACTED",
"redirect_uris":["http://localhost:8080/"],
"javascript_origins":["http://localhost:8080"]}}

我也尝试过使用http://my_actual_domain.com:5000/ 进行redirect_uris,但它仍然返回相同的错误。

我不明白 redirect_uris 应该是什么意思?我在顶部链接的指南中没有提到它

【问题讨论】:

    标签: android python api web oauth


    【解决方案1】:

    重定向 uri 是您在创建 OAuth 客户端 ID 时提供的内容。您在应用程序中使用的那个应该与您在请求客户端 ID 时提供的那个相匹配。

    请确保此配置正确。

    【讨论】:

      猜你喜欢
      • 2020-08-08
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      • 2013-01-15
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多