Python GoogleOAuth2命令行示例
谷歌有一个OAuth2客户端的例子 我对OAuth2完全陌生,我希望在将OAuth2与我的应用程序集成之前,这个示例能够正常工作。我所做的工作如下:Python GoogleOAuth2命令行示例,python,google-api,oauth-2.0,google-api-python-client,Python,Google Api,Oauth 2.0,Google Api Python Client,谷歌有一个OAuth2客户端的例子 我对OAuth2完全陌生,我希望在将OAuth2与我的应用程序集成之前,这个示例能够正常工作。我所做的工作如下: 注册测试应用程序 获取客户端ID和客户端机密 将这些值配置为client_secrets.json 运行测试应用程序:python版主.py 该应用程序打开一个浏览器,我可以(作为用户)授权该应用程序访问我的帐户。但谷歌的抱怨是这样的(400个错误请求): 我猜localhost:8080来自由moderator.py启动的内部web服务器。我的问
python版主.py
我对OAuth2感到非常困惑,任何帮助都将不胜感激。在OAuth2.0中,redirect_uri参数通常向提供程序注册。提供程序还应强制执行仅https重定向uri
您需要在这里向Google注册重定向uri:首先,如果我的回答不太准确,很抱歉,因为我对OAuth(甚至python)也很陌生。。。如果来得太晚,我也很抱歉,我通常不会访问这里 你试过使用这个(对我有用): 重定向_URI='urn:ietf:wg:oauth:2.0:oob' 选中此项:
我有一段完整的OAuth流工作的代码。也许可以尝试在Google注册您的外部IP(可能需要在路由器上进行一些端口转发)?如果失败,也许您可以使用Python的SimpleServer,注册您的IP并让此服务器处理重定向。您的重定向\u uri设置为“”,因为您传递了一个默认(我不知道如何描述)flags参数来运行\u流(流、存储、标志) 如果查看“为run_flow()定义”函数,您会发现:
It presumes it is run from a command-line application and supports the
following flags:
``--auth_host_name`` (string, default: ``localhost``)
Host name to use when running a local web server to handle
redirects during OAuth authorization.
``--auth_host_port`` (integer, default: ``[8080, 8090]``)
Port to use when running a local web server to handle redirects
during OAuth authorization. Repeat this option to specify a list
of values.
``--[no]auth_local_webserver`` (boolean, default: ``True``)
Run a local web server to handle redirects during OAuth
authorization.
我已经在GoogleAPI控制台中注册了我的测试应用程序,但我正在从命令行运行该应用程序(它被称为“命令行示例”)。我没有可以重定向到的URI。我需要在何处或如何运行此示例,以便用户能够授权我的应用程序访问用户数据。这只是了解OAuth2如何工作的一个简单示例,但我无法让它运行。
It presumes it is run from a command-line application and supports the
following flags:
``--auth_host_name`` (string, default: ``localhost``)
Host name to use when running a local web server to handle
redirects during OAuth authorization.
``--auth_host_port`` (integer, default: ``[8080, 8090]``)
Port to use when running a local web server to handle redirects
during OAuth authorization. Repeat this option to specify a list
of values.
``--[no]auth_local_webserver`` (boolean, default: ``True``)
Run a local web server to handle redirects during OAuth
authorization.