我开始使用 Vkontakte android SDK ,并且做得很好)。我做了授权,并获得了userFirstName,userLastName和userPhoto。但我不知道如何从用户墙获取用户墙或用户帖子。它应该是类似的,我在logcat中看到响应#2,但我真的不知道如何解析它???
//Prepare request for userName and photo
final VKRequest request1 = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS, "photo_100, contacts"));
//Prepare request for userWall
final VKRequest request2 = VKApi.wall().get(VKParameters.from(VKApiConst.OWNER_ID));
//Parallel executing requests
VKBatchRequest batch = new VKBatchRequest(request1, request2);
batch.executeWithListener(new VKBatchRequest.VKBatchRequestListener() {
@Override
public void onComplete(VKResponse[] responses) {
super.onComplete(responses);
//Work with responses
//*****
//UserName and photo response
//*****
VKApiUserFull user = ((VKList<VKApiUserFull>) responses[0].parsedModel).get(0);
Ion.with(ivUserPhoto).placeholder(R.drawable.ic_launcher)
.error(R.drawable.ic_launcher)
.load(user.photo_100);
tvUserName.setText(user.first_name + " " + user.last_name);
//********
//Wall response similar sa userResponse...
//********
VKApiPost mPost = ((VKList<VKApiPost>) responses[1].parsedModel).get(0);
Log.e("post name", mPost.toString());
}
@Override
public void onError(VKError error) {
//Error;
}
});
答案 0 :(得分:1)
这里是正确的代码,tnx Dreddik &lt; - vk android sdk developer。
VKRequest request2 = VKApi.wall().get(VKParameters.from(VKApiConst.OWNER_ID, VKSdk.getAccessToken().userId, VKApiConst.EXTENDED, 1));
request2.executeWithListener(new VKRequestListener() {
@Override
public void onError(VKError error) {
}
@Override
public void onComplete(VKResponse response) {
VKList<VKApiPost> posts = (VKList<VKApiPost>) response.parsedModel;
VKApiPost post = posts.get(0);
Log.d("Post:", post.toString());
}
});