Error when using Box SDK Java
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 "Couldn't connect to the Box API due to a network error" 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 using Box SDK for Java I am facing this issue. Below is the code excerpt which uses SDK -
BoxAPIConnection api = new BoxAPIConnection("XXXXXXXXXXXXXXXX");
BoxUser.Info userInfo = BoxUser.getCurrentUser(api).getInfo();
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
rootFolder.getMetadata(); ==> HERE I AM GETTING ERROR
I also tried to use apache HttpClient with HttpGet by pasting the API and passing token in header and it worked perfectly fine.
So I am able to connect to Box API with PostMan and traditional Java Code (using Apache HTTP). This clearly shows there is no network error. But only when I use Box SDK, I get Network error.
Please help in figuring out the issue.
Thanks in Advance.
-
Thanks for your reply. My code is working now. Although some behavior I am not able to understand like -
Below Code does not work:
BoxDeveloperEditionAPIConnection serviceAccountConnection = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, accessTokenCache)==Gives Error
BoxDeveloperEditionAPIConnection serviceAccountConnection = BoxDeveloperEditionAPIConnection.getAppUserConnection(User_Id, boxConfig, accessTokenCache)==Gives ErrorBelow Code works:
BoxDeveloperEditionAPIConnection serviceAccountConnection = new BoxDeveloperEditionAPIConnection(User_Id, DeveloperEditionEntityType.USER, boxConfig, accessTokenCache)
Also, can you let me know if Box SDK works with Java 6. When I tried it gave me error for Jose dependency since its only supported on Java 7 onwards. Is there any alternative library that I can use to make my code work on Java 6?
-
The two static methods that you list as not working don't just construct the BoxDeveloperEditionAPIConnection, but they also craft a JWT and make the API request to exchange the JWT for an access token by calling the authenticate() method on the BoxDeveloperEditionAPIConnection. If you're using an older version of Java that the SDK does not support, then it's probably that authenticate() method where the error is thrown. This makes sense to me, because that method relies on jose4j to construct the JWT. Unfortunately, the SDK does not support Java versions less than 7 and I'm not aware of any workarounds to use the necessary JWT functionality on older versions.
サインインしてコメントを残してください。
コメント
3件のコメント