我花了几个小时尝试解决如何使用 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/