python - 使用 Python 请求库获取 Google Oauth2 token

标签 python oauth-2.0

我花了几个小时尝试解决如何使用 python 请求库获取 oauth2 token 的问题。我做错了什么?

  r=requests.post("https://accounts.google.com/o/oauth2/token",
                            headers={
                                'content-type':'application/x-www-form-urlencoded'},
                            params={
                                'code':request.GET['code'],
                    'client_id':'11111111111.apps.googleusercontent.com',
                                'client_secret':'my secert',
                                'redirect_uri':'http://localhost/etc'
                                'grant_type':'authorization_code'})

最佳答案

请求的数据必须在正文中发送,而不是在查询字符串中

在您的代码中将 params= 更改为 data=

有关详细信息,请参阅此讨论: https://groups.google.com/forum/#!topic/oauth2-dev/ahP0cz2ao0o

关于python - 使用 Python 请求库获取 Google Oauth2 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18014479/

相关文章:

javascript - 如何为从移动和 JavaScript Web 应用程序访问的 rest API 实现基于 token 的 OAuth 2.0 身份验证

python - 如何使用 Popen.communicate(在 Linux 上)传递击键(ALT+TAB)?

Python 二进制搜索(最大迭代次数)

python - 使用 doxygen 记录 Python 包

c# - 更改 OWIN .expiration 和 .issued 日期的 DateTime 格式

c# - WCF中的Oauth 2.0服务提供者

oauth - Google OAuth 安装的应用程序流程 : redirect_uri_mismatch

python - 识别 lex 中的关键字对

python - INSERT datetime variable INTO VALUES 的语法是什么

python - Graph API 以编程方式验证用户身份