Reputation: 21
Please help me in getting the user details for the current user in the BoxApi v2 for android
The code which I am using the user details is as follows:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
BoxAndroidClient client = null;
if (Activity.RESULT_OK != AUTH_REQUEST) {
Toast.makeText(this, "fail", Toast.LENGTH_LONG).show();
} else {
BoxAndroidOAuthData oauth = data
.getParcelableExtra(OAuthActivity.BOX_CLIENT_OAUTH);
BoxAndroidOAuthData moath = data
.getParcelableExtra(OAuthActivity.USER_SERVICE);
client = new BoxAndroidClient(HelloWorldApplication.CLIENT_ID,
HelloWorldApplication.CLIENT_SECRET, null, null);
client.authenticate(oauth);
accestoken = oauth.getAccessToken().toString();
System.out.println("AUTHDATA" + oauth.getAccessToken().toString());// client.getUsersManager().getCurrentUser(requestObj).toString()
// + oauth.getAccessToken().toString());
BoxUser user = new BoxUser();
System.out.println("ID" + user.getId());
if (client == null) {
Toast.makeText(this, "fail", Toast.LENGTH_LONG).show();
} else {
((HelloWorldApplication) getApplication()).setClient(client);
Toast.makeText(this, "authenticated", Toast.LENGTH_LONG).show();
}
}
BoxDefaultRequestObject requestObject = null;
List<BoxUser> userList = null;
try {
userList = client.getUsersManager().getAllEnterpriseUser(
requestObject, null);
} catch (BoxRestException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BoxServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AuthFatalFailureException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (BoxUser usr : userList) {
System.out.println("Addr: " + usr.getAddress());
System.out.println("Name : " + usr.getName());
System.out.println("Login : " + usr.getLogin());
}
}
I am getting the exception as networkonmainthreadexception...
Can anybody please help me?
Upvotes: 1
Views: 247
Reputation: 1383
Make sure your access token is up to date. Also, looking at your code, why have you set
BoxDefaultRequestObject requestObject = null;
Instead do:
BoxDefaultRequestObject requestObject = new BoxDefaultRequestObject()
Otherwise the box library will get a null pointer exception. It gets the JSON parser from the request object.
Let me know if this works.
Upvotes: 0
Reputation: 2599
Getting current user info in the raw api is done with a call to GET /users/me
Not sure what that looks like in the Java, but probably something more like :
user = client.getUsersManager().getCurrentUser
Upvotes: 1