获取访问令牌的box api错误:无效的grant_type参数或参数丢失

时间:2013-01-10 01:53:10

标签: javascript oauth-2.0 box-api

我正在尝试获取访问令牌并使用以下网址发布HTTP请求并接收

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

错误消息。无论我尝试什么。我收到代码后发帖秒,所以我不认为代码可能是失败点。

发布https://api.box.com/oauth2/token?grant_type=authorization_code&code=H23sCQmlzsEJSEyhKXj19yb1LWew9MPk&client_id=xyz&client_secret=123

我做错了什么?

2 个答案:

答案 0 :(得分:5)

我想您可能会尝试在请求正文中发送grant_type=...,而不是查询字符串。

以下是该特定请求的文档示例:

curl https://api.box.com/oauth2/token \
-d 'grant_type=authorization_code&code={your_code}&client_id={your_client_id}&client_secret={your_client_secret}' \
-X POST

答案 1 :(得分:1)

我遇到了同样的问题而John的解决方案也奏效了。您不必像获取访问代码那样在url中包含参数,而是需要将它们编码为POST数据。

我正在使用Chrome的Postman加载项,我在点击Key-Value按钮后在较低x-www-form-urlencoded字段中输入参数。