1
votes

I need to get the Access Token in ajax, the following example is in Curl how can i do the same in ajax call?

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

2
Take a look at my updated answer. - Alexandre Santos

2 Answers

0
votes

i send ajax as following: $.ajax({ url: 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%20%3D%20https%3A%2F%2Fwww.box.com/api/oauth2/token', type: 'POST', dataType: 'jsonp', processData: false, data: {grant_type:'authorization_code', client_id:'3d2yi406h9eoykhucw9b8w3d2oky7kdy' , client_secret:'YQtHVIoutEnKLNpbmjk3CvZ72bshnpGk'}, complete: function (data) { alert(JSON.stringify(data)); }, error: function(){ alert("Cannot get data"); } })

XMLHttpRequest {statusText: "", status: 0, response: "", responseType: "", responseXML: null…} Alert: {"statusText":"OK","status":200,"response":"","responseType":"","responseXML":null,"responseText":"","upload":{"ontimeout":null,"onprogress":null,"onloadstart":null,"onloadend":null,"onload":null,"onerror":null,"onabort":null},"withCredentials":false,"readyState":4,"timeout":0,"ontimeout":null,"onprogress":null,"onloadstart":null,"onloadend":null,"onload":null,"onerror":null,"onabort":null}

As you can see i get an status:200 but the response is empty, and not including an "Access token", why?

0
votes

If you look here: http://developers.box.com/oauth/

You will see that in the section "Getting the Access Token" that you can provide a redirect_uri.

When you register your application with Box they present you a page where you enter what is the redirect url that will be used (see example from link above). However, you can override that and provide the redirect url on your call during oAuth. So all you have to do is provide a page on your own web site which will hold the state change (either success or failure), and check on the state.

I saw that you added another detail on the request.

Note that the request is being done to https://query.yahooapis.com/v1/public/y... instead of http://developers.box.com/oauth/. That redirection is probably changing the query or the headers. Try updating and resubmitting. Let me know if it doesn't work.