我正在我的 django 应用程序中设置 Google Oauth 2。我能够获取代码,但是当我尝试将其交换为访问 token 时,我收到 Bad Request
错误。这是我的代码:
code = request.GET['code']
state = request.GET['state']
access_token_url = "https://www.googleapis.com/oauth2/v3/token"
payload = {
'grant_type' : "authorization_code",
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'code': code,
'redirect_uri': "http://127.0.0.1:8888/home",
}
payload = urllib.urlencode(payload)
r = urllib2.Request(access_token_url, payload, headers={"Content-type" : "application/x-www-form-urlencoded"})
response = urllib2.urlopen(r)
可能出了什么问题?
当我使用 POSTMAN(谷歌浏览器应用程序)尝试相同的操作时,我得到了
{
"error": "invalid_request",
"error_description": "Required parameter is missing: grant_type"
}
我知道这里有类似的问题,但我仍然无法找出错误。
最佳答案
这是一个愚蠢的错误。我提供了错误的 redirect_uri
。不管怎样,来自 google API 的错误消息没有多大帮助。
关于python - Google Oauth2 中的 400 错误请求访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31158590/