启用服务器端访问Google API时出现redirect_uri_mismatch错误

时间:2017-10-04 02:02:41

标签: android python api web oauth

我有一个带有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应该是什么意思?在我在顶部链接的指南中未提及

1 个答案:

答案 0 :(得分:0)

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

请确保正确配置。

enter image description here