0
votes

I am trying to develop one web application using JAVA to retrieve files and folders from box.com.

For this I am using OAuth Process. In this process I have taken "access_token". By using this "aceess_token" I need to make a request to API V2.

For this, box-api people have given One URL:

https://www.box.com/api/2.0/folders/0 -H "Authorization: Bearer {acceess_token}"

So, My questions are:

  • What is "Authorization : Bearer"?
  • How to append this string to url?
  • How to pass "access_token"?
4

4 Answers

1
votes

Lot of (general) questions there. Oauth is not a simple subject. I have found this http://tutorials.jenkov.com/oauth2/index.html to explain it in a very nice, concise way.

1
votes
URL url = new URI("https", "www.box.com", "/api/oauth2/token",null).toURL();
urlConn.setRequestProperty("Authorization", "Bearer " + accessToken);
if (urlConn.getResponseCode() == 200)
{
     //get stringBuffer filled
}
0
votes

You may want to try the box java sdk: https://github.com/box/box-java-sdk-v2 It supports OAuth flow but is lack of OAuth UI now. There is also a hello world example showing how to implement UI for the OAuth flow: https://github.com/box/box-java-sdk-v2/wiki/HelloWorld

0
votes

Sarath, "Authorization: Bearer " here is not a URL parameter. You don't want to be appending it to the URL. It's actually a key-value pair of HTTP Header and value.

That is, you need to set the "Authorization" header to the value "Bearer "

So here, your request might look like:

URL url = new URL("https://api.box.com/2.0/folders/0");
UrlConnection conn = url.openConnection();
conn.setRequestProperty("Authorization", "Bearer my_access_token");

Like Jian said, I'd recommend you use the Box Java SDK to make it a bit easier to deal with the networking aspects here.