我正在使用Facebook SDK for android来获取朋友列表和用户的家乡。我在登录时要求read_friendlists
权限以及user_hometown
权限。我甚至尝试过user_friends
权限。这工作正常,我登录时要求这些权限。我已经批准了许可,然后发送了我的请求,如下所示:
Request meRequest = Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (Model.this.session == Session.getActiveSession()) {
if (user != null) {
String hometown = "Location not available";
if(user.asMap().get("hometown") != null) { //Intead of user.asMap().get("hometown"), I tried with user.getLocation() as well, no use
hometown = user.asMap().get("hometown").toString();
}
}
}
}
});
meRequest.executeAsync();
但即使我将家乡设置为我的帐户,它仍会显示Location not available
。
现在我尝试访问用户好友列表(在收到来自我请求的回复之后),如下所示:
final ArrayList<String> friendNames = new ArrayList<String>();
Request friendRequest = Request.newMyFriendsRequest(session, new Request.GraphUserListCallback() {
@Override
public void onCompleted(List<GraphUser> users, Response response) {
for (GraphUser user1 : users) {
friendNames.add(user1.getName());
}
}
});
friendRequest.executeAsync();
但users
列表始终为空,导致friendNames
arrayList始终为空。我在这做错了什么?如何纠正它?