简体   繁体   中英

access token request with box api

I have a problem sending the access token request with box api and the rest client gem :

request

access_token_params = {
      grant_type: 'authorization_code',
      code: params[:code],
      client_id: box_params[:client_id],
      client_secret: box_params[:client_secret]
    }

    RestClient.post('https://app.box.com/api/oauth2/token', params: access_token_params){ |response, request, result, &block|
      check_request_success(response, "send_access_token")
    }

with:

def box_params
    {
      client_id: "my_id",
      client_secret: "my_secret"
    }
  end

error:

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

First

Your RestClient.post() function incorrect. Because it is a post you should not have params: hash but rather the payload itself. This is because post requests don't have params in the url, but rather in a payload in the body of the request.

Second

The Box API Docs & Oauth Tutorial page reference two endpoints. The correct endpoint for the request on the API docs: https://api.box.com/oauth2/token

Try this:

  RestClient.post('https://api.box.com/oauth2/token', access_token_params ){ |response, request, result, &block|

            check_request_success(response, "send_access_token")   
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM