Java box SDK Connection Problem
Hi,
I am new to Box and using the below Java code to list out the files in my folder. But, I am getting BoxAPIException as shown below.
Code:
BoxAPIConnection api = new BoxAPIConnection("Developer Token");
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
for (BoxItem.Info itemInfo : rootFolder) {
System.out.format("[%s] %s\n", itemInfo.getID(), itemInfo.getName());
}
Exception:
Exception in thread "main" com.box.sdk.BoxAPIException: Couldn't connect to the Box API due to a network error.
at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:451)
at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:265)
at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:240)
at com.box.sdk.JSONIterator.loadNextPage(JSONIterator.java:74)
at com.box.sdk.JSONIterator.loadNextJsonObject(JSONIterator.java:90)
at com.box.sdk.JSONIterator.hasNext(JSONIterator.java:32)
at com.box.sdk.BoxItemIterator.hasNext(BoxItemIterator.java:28)
at com.visa.sample.FirstFirdayoftheYear.getAllPersonNames(FirstFirdayoftheYear.java:18)
at com.visa.sample.FirstFirdayoftheYear.main(FirstFirdayoftheYear.java:12)
Caused by: java.net.UnknownHostException: api.box.com
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:449)
... 8 more
Any help appricated.
Thanks & Regards,
VT
-
The error message says that it's an IOException caused by an UnkownHostException for api.box.com — the docs for that exception indicate that it's thrown when the IP address cannot be resolved for a host. Are you able to reach api.box.com when making requests manually through a tool like curl or Postman? Is there a chance you're behind a firewall that blocks access to the API?
-
Dear All,
I am able to connect Box APIs using PostMan by dev token generated through portal. However, when I try to do the same thing using Box Java SDK, I am getting UnknownHostException for api.box.com and upload.box.com
Since I am able to get response with PostMan, so this certainly is not a network or firewall issue. Only when I am trying to run my java code from eclipse I am facing this issue. Below is the code excerpt which uses SDK -
BoxAPIConnection api = new BoxAPIConnection("CClWUDaNOriFxEljGYGn5hmAwfpwQEUf");
BoxUser.Info userInfo = BoxUser.getCurrentUser(api).getInfo();
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
rootFolder.getMetadata(); ==> HERE I AM GETTING ERROR UnknownHostExceptionI also tried to use apache HttpClient with HttpPost by pasting the API and passing token in header. But at that time I get 403 error with reason as access_denied_insufficient_permissions.
Please help in figuring out the issue.
Thanks in Advance.
サインインしてコメントを残してください。
コメント
2件のコメント