Reputation: 1
Developer token works great, but I need a permanent solution. I'm building a personal site and just need to read the items in the folder, don't need any user authentication.
When I try using cliend id and secret
this.api = new BoxAPIConnection(clientID, clientSecret);
I get this exception:
Exception in thread "main" com.box.sdk.BoxAPIResponseException: The API returned an error code [401 | .0e*******]
at com.box.sdk.BoxAPIResponse.<init>(BoxAPIResponse.java:92)
at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:675)
at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:381)
at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:348)
at com.box.sdk.JSONIterator.loadNextPage(JSONIterator.java:75)
at com.box.sdk.JSONIterator.loadNextJsonObject(JSONIterator.java:97)
at com.box.sdk.JSONIterator.hasNext(JSONIterator.java:32)
at com.box.sdk.BoxItemIterator.hasNext(BoxItemIterator.java:28)
at servicesHttpConnect.boxConnect.findFileBoxItemObject(boxConnect.java:114)
at servicesHttpConnect.boxConnect.itemsInFolder(boxConnect.java:95)
at servicesHttpConnect.boxConnect.main(boxConnect.java:131)
(My app is authorized in the admin console) So how can I log in to box? Thanks!
Upvotes: 0
Views: 1111
Reputation: 62
With the example you are not passing in Oauth access token. You are just passing in Box API's ClientID and secret. Those are not enough to access Box Resources.
https://developer.box.com/guides/authentication/oauth2/
I would recommend checking out the SDK's Authentication section for details on how to obtain and pass an access token to the SDK.
https://github.com/box/box-java-sdk/blob/master/doc/authentication.md
I would be careful using JWT since this is a very powerful token and could lead to data loss if you aren't careful how you deploy your app.
Since in your use case you already know which folder you want to access, and assuming it's limited number of folders, I would recommend inviting a new user to those folders and authenticate as that user. Use the access token obtained and pass it to the SDK. That way you will only be able to access the folders you want and limits data loss risks.
https://github.com/box/box-java-sdk/blob/master/doc/authentication.md#manual-token-creation
Upvotes: 1