Google OAuth2命令行示例

dan*_*ast 7 python google-api oauth-2.0 google-api-python-client

谷歌在这里有一个OAuth2客户端的例子

我完全是OAuth2的新手,我希望在我将OAuth2与我的应用程序集成之前让这个示例正常工作.我所做的是以下内容:

  1. 注册测试应用程序
  2. 获取客户端ID和客户端密钥
  3. 将这些值配置到client_secrets.json中
  4. 运行测试应用程序: python moderator.py

该应用程序打开一个浏览器,我可以(作为用户)授权应用程序访问我的帐户.但谷歌这样抱怨(400 Bad Request):

Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:8080/ did not match a registered redirect URI
Learn more
Request Details
from_login=1
scope=https://www.googleapis.com/auth/moderator
response_type=code
access_type=offline
redirect_uri=http://localhost:8080/
approval_prompt=auto
as=-xxxxxxxxxxxxx
pli=1
client_id=xxxxxxxxxxx.apps.googleusercontent.com
authuser=0
hl=en
Run Code Online (Sandbox Code Playgroud)

我想localhost:8080来自一个由moderator.py启动的内部Web服务器.我的问题是:有人得到这个例子吗?我需要哪些其他组件(apache配置,DNS,...)

我对OAuth2非常困惑,任何帮助将不胜感激.

Col*_*lau 0

在 OAuth 2.0 中,redirect_uri 参数通常是向提供者注册的。提供商还应该强制执行仅限 https 的 redirect_uri。

您需要在此处向Google注册redirect_uri: https: //code.google.com/apis/console/ ?pli=1#access

  • 我已经在 Google API 控制台中注册了我的测试应用程序,但我正在从命令行运行该应用程序(称为“命令行示例”)。我没有可以重定向到的 URI。我需要在哪里或如何运行此示例,以便用户能够授权我的应用程序访问用户数据。这只是一个了解 OAuth2 如何工作的简单示例,但我无法运行它。 (3认同)