启用对googleapi的服务器端访问时,重定向\u uri \u不匹配错误

2024-04-20 13:05:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个带有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:重定向uri不匹配

这是你的名字机密.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"]}}

我也尝试过对重定向uri使用http://my_actual_domain.com:5000/,但它仍然返回相同的错误。你知道吗

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


Tags: https服务器comclienttokenauthidjson
1条回答
网友
1楼 · 发布于 2024-04-20 13:05:20

重定向uri是在创建OAuth客户机ID时提供的。应用程序中使用的uri应该与请求客户机ID时提供的uri匹配

请确保此配置正确。你知道吗

enter image description here

相关问题 更多 >