box api error getting the access token: Invalid gr

2020-07-23 06:09发布

问题:

I am trying to get an access token and using the following url to POST the HTTP request and receiving

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

error message . No matter what I try. I am posting seconds after receiving the code so I dont think the code could be the failure point.

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

What am I doing wrong?

回答1:

I think you might try sending the grant_type=... in the request body, not as a query string.

Here's the documentation example for that particular request:

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



回答2:

I had been having this same problem and John's solution worked. Instead of including the parameters in the url as you do when getting the access code, you need to encode them as POST data.

I'm using the Postman add-in for Chrome and I enter the parameters in the lower Key-Value fields after clicking the x-www-form-urlencoded button.