问题描述
我不知道我做错了什么,但是每次我尝试获取令牌时(当然是在用户身份验证之后),结果始终是无效的grant_type参数或缺少参数
I don't know what I do wrong, but everytime I tried to obtain the token (after user authentication of course), the result is always Invalid grant_type parameter or parameter missing
可能与
这是我的提琴手结果:
POST https://api.box.com/oauth2/token HTTP/1.1
Host: api.box.com
Content-Length: 157
Expect: 100-continue
Connection: Keep-Alive
grant_type=authorization_code&code=nnqtYcoik7cjtHQYyn3Af8uk4LG3rYYh&client_id=[myclientId]&client_secret=[mysecret]
结果:
HTTP/1.1 400 Bad Request
Server: nginx
Date: Thu, 07 Mar 2013 11:18:36 GMT
Content-Type: application/json
Connection: keep-alive
Set-Cookie: box_visitor_id=5138778bf12a01.27393131; expires=Fri, 07-Mar-2014 11:18:35 GMT; path=/; domain=.box.com
Set-Cookie: country_code=US; expires=Mon, 06-May-2013 11:18:36 GMT; path=/
Cache-Control: no-store
Content-Length: 99
{"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}
即使在curl示例之后也给出了相同的错误。任何帮助将不胜感激。
Even following the curl example gives the same error. Any help would be appreciated.
编辑:尝试使用其他redirect_uri参数,但仍存在相同错误
tried with additional redirect_uri params but still the same error
POST https://api.box.com/oauth2/token HTTP/1.1
Content-Type: application/json; charset=UTF-8
Host: api.box.com
Content-Length: 187
Expect: 100-continue
Connection: Keep-Alive
grant_type=authorization_code&code=R3JxS7UPm8Gjc0y7YLj9qxifdzBYzLOZ&client_id=*****&client_secret=*****&redirect_uri=http://localhost
结果:
HTTP/1.1 400 Bad Request
Server: nginx
Date: Sat, 09 Mar 2013 00:46:38 GMT
Content-Type: application/json
Connection: keep-alive
Set-Cookie: box_visitor_id=513a866ec5cfe0.48604831; expires=Sun, 09-Mar-2014 00:46:38 GMT; path=/; domain=.box.com
Set-Cookie: country_code=US; expires=Wed, 08-May-2013 00:46:38 GMT; path=/
Cache-Control: no-store
Content-Length: 99
{"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}
推荐答案
像Box要求正确的 Content-Type:application / x-www-form-urlencoded
请求标头,以及对参数进行正确的URL编码。似乎同样适用于刷新和撤消请求。
Looks like Box requires a correct Content-Type: application/x-www-form-urlencoded
request header in addition to properly URL encoding the parameters. The same seems to apply to refresh and revoke requests.
此外,根据, redirect_uri
仅
这篇关于方框oauth2:无效的grant_type参数或缺少参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!