Box API通过python

时间:2015-09-10 23:16:53

标签: python api access-token box

先谢谢你的帮助。我在自述页面上通过这个网站获得了授权码:https://app.box.com/api/oauth2/authorize?response_type=code&client_id=MY_CLIENT_ID&state=security_token%3DKnhMJatFipTAnM0nHlZA

通过python发送 access_token 。但是收到 invalid_request 错误。我通过邮递员尝试的结果相同。 附上我的代码和错误信息,我理解错了吗?

url = 'https://api.box.com/oauth2/token'
payload = {'grant_type':'authorization_code','code':auth_code,'client_id':'ID','client_secret':'SECRET'}
r = requests.post(url, data=json.dumps(payload))
json_r = r.json()
print json_r

错误讯息:

{
  "error": "invalid_request",
  "error_description": "Invalid grant_type parameter or parameter missing"
}

1 个答案:

答案 0 :(得分:0)

问题是当requests.post函数的data参数需要普通字典时,您将POST有效内容编码为JSON字符串。 所以这样做就应该有效:

r = requests.post(url, data=payload)
相关问题