【问题标题】:Google oauth authorization error. 'Error 400: redirect_uri_mismatch'Google oauth 授权错误。 '错误 400:redirect_uri_mismatch'
【发布时间】:2021-10-14 15:26:13
【问题描述】:

为什么我在尝试授权我的 Oauth 应用时收到此错误。

Authorization Error
Error 400: redirect_uri_mismatch
You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy. \n\nIf you're the app developer, register the redirect URI in the Google Cloud Console.
Learn more
Request Details 
redirect_uri=http://localhost:8080/

重定向 URL https://localhost:8080 已在谷歌云控制台中注册,但我仍然收到此错误。

Python 文件

from google_auth_oauthlib.flow import InstalledAppFlow

flow = InstalledAppFlow.from_client_secrets_file('client_secrets.json',
scopes = ['https://www.googleapis.com/auth/youtube.readonly'])

flow.run_local_server(port=8080)

client_secrets.json

{
  "web": {
    "client_id": "$id",
    "project_id": "youtube-constant-update",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "$secret",
    "redirect_uris": ["https://localhost:8080"]
  }
}

感谢任何类型的支持/帮助

谢谢

【问题讨论】:

    标签: python-3.x api google-cloud-platform oauth-2.0 google-oauth


    【解决方案1】:

    httphttps 是不同的 URI。您注册了 https,但错误消息是针对 http。 URI 包含方案。

    注册重定向 URI http://localhost:8080/

    【讨论】:

    • 我试过了,但一直报错:无效重定向:必须以公共顶级域(如 .com 或 .org)结尾。
    • @AmiraElsayedIsmail - 创建一个新问题。在您的问题中包括您在哪里运行代码。您不能将 localhost 用于后端。在桌面上开发时可以使用 localhost(Web 浏览器与您的代码在同一台机器上运行)。
    • 我已经有另一个问题:stackoverflow.com/questions/70559158/…,我正在从 localhost 运行代码
    • @AmiraElsayedIsmail - 您没有说明您在哪里运行此代码,也没有显示代码或如何配置 OAuth 客户端。细节有助于解决问题。
    猜你喜欢
    • 1970-01-01
    • 2012-07-14
    • 2013-07-31
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    相关资源
    最近更新 更多