请帮助我在BoxApi v2 for android
中获取当前用户的用户详细信息我使用用户详细信息的代码如下:
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());
}
}
我得到例外的是networkonmainthreadexception ...
有人可以帮帮我吗?
答案 0 :(得分:1)
通过调用GET / users / me
获取原始API中的当前用户信息不确定Java中的内容,但可能更像是:
user = client.getUsersManager().getCurrentUser
答案 1 :(得分:0)
确保您的访问令牌是最新的。另外,查看代码,为什么要设置
BoxDefaultRequestObject requestObject = null;
取而代之的是:
BoxDefaultRequestObject requestObject = new BoxDefaultRequestObject()
否则,框库将获得空指针异常。它从请求对象中获取JSON解析器。
让我知道这是否有效。