I've been recently trying to implement Box in my Android app. I know how to launch the authentication activity and get BoxAndroidClient object ready to operate on it, but I have got no idea on how to save tokens (SharedPreferences?), load them and then authenticate using loaded tokens, so the user won't have to login to his box account every time he would like to access his files in cloud.
I tried to refresh previously saved tokens (because of Exception that told me that my AccessToken is incorrect).
BoxAndroidOAuthData data = new BoxAndroidOAuthData(new HashMap<String, Object>(){
private static final long serialVersionUID = 1L;
{
put(BoxAndroidOAuthData.FIELD_ACCESS_TOKEN, prefs.acc);
put(BoxAndroidOAuthData.FIELD_REFRESH_TOKEN, prefs.ref);
put(BoxAndroidOAuthData.FIELD_EXPIRES_IN, prefs.exp);
put(BoxAndroidOAuthData.FIELD_TOKEN_TYPE, prefs.typ);
}
});
data = new BoxAndroidOAuthData(client.getOAuthManager().refreshOAuth(BoxOAuthRequestObject.refreshOAuthRequestObject(data.getRefreshToken(), C, S)));
And I've got another exception:
07-02 22:07:16.433: W/System.err(4684): com.box.restclientv2.exceptions.BoxRestException: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'type' that is to contain type id (for class com.box.boxjavalibv2.dao.BoxServerError)
07-02 22:07:16.433: W/System.err(4684): at [Source: java.io.StringReader@b55b2c78; line: 1, column: 69]
07-02 22:07:16.433: W/System.err(4684): at com.box.restclientv2.responseparsers.DefaultBoxJSONResponseParser.parse(DefaultBoxJSONResponseParser.java:75)
07-02 22:07:16.433: W/System.err(4684): at com.box.boxjavalibv2.responseparsers.ErrorResponseParser.parse(ErrorResponseParser.java:31)
07-02 22:07:16.433: W/System.err(4684): at com.box.restclientv2.responses.DefaultBoxResponse.parseResponse(DefaultBoxResponse.java:51)
07-02 22:07:16.433: W/System.err(4684): at com.box.boxjavalibv2.resourcemanagers.BoxResourceManager.getResponseAndParse(BoxResourceManager.java:168)
07-02 22:07:16.433: W/System.err(4684): at com.box.boxjavalibv2.resourcemanagers.BoxResourceManager.getResponseAndParseAndTryCast(BoxResourceManager.java:143)
07-02 22:07:16.433: W/System.err(4684): at com.box.boxjavalibv2.resourcemanagers.BoxOAuthManager.refreshOAuth(BoxOAuthManager.java:68)
As I haven't found any tutorials on how to properly do the auth part in Java (samples included in SDK don't cover any method of saving tokens), could anyone provide a good example for that?