Google 访问令牌的 Oauth2 中的 400 错误请求
400 Bad Request in Google Oauth2 for access token
我正在我的 Django 应用程序中设置 Google Oauth 2。我能够获取代码,但是当我尝试将其交换为访问令牌时,出现 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(google chrome 应用程序)时,我得到
{
"error": "invalid_request",
"error_description": "Required parameter is missing: grant_type"
}
我知道这里有类似的问题,但我仍然无法找出错误。
添加到负载
grant_type=authorization_code
这是一个愚蠢的错误。我给错了redirect_uri
。不管怎样,来自 google API 的错误消息并没有太大帮助。
我正在我的 Django 应用程序中设置 Google Oauth 2。我能够获取代码,但是当我尝试将其交换为访问令牌时,出现 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(google chrome 应用程序)时,我得到
{
"error": "invalid_request",
"error_description": "Required parameter is missing: grant_type"
}
我知道这里有类似的问题,但我仍然无法找出错误。
添加到负载
grant_type=authorization_code
这是一个愚蠢的错误。我给错了redirect_uri
。不管怎样,来自 google API 的错误消息并没有太大帮助。