[英]Get user Friends GraphLocation with Android - Facebook SDK and GraphUser
我在从Android应用程序上的最终用户Facebook朋友列表中获取位置数据时遇到了一些麻烦。
到目前为止,我可以成功打开Facebook会话,存储和还原访问令牌并获取用户朋友列表。
如Android Facebook SDK> 3.0中所定义,Facebook用户数据在名为GraphUser
的对象中具有强类型。
为了获取好友列表,我使用了Request.newMyFriendsRequest
,它成功后为我提供了GraphUsers
列表。
不幸的是,尽管我为自己的努力提供了必要的权限,但我无法检索到最终用户朋友的姓名和ID以外的信息……仅此而已:每个最终用户Facebook朋友都是一个仅包含其姓名和ID的GraphUser。
这是我使用的权限列表:
"user_status", "read_friendlists", "email", "user_location", "friends_location"
SDK使用Facebook LoginButton,告知最终用户该应用确实需要上述权限列表。
但是,当我想使用Graphuser.getLocation时,我会得到null
值。 没有城市,没有州,没有邮政编码,什么都没有。
这是用于检索最终用户数据的代码段:
public final void setCurrentUser(final Context context) {
if (this.session != null && this.session.isOpened()) {
final Request requestCurrentUserProfile = Request.newMeRequest(
this.session, new Request.GraphUserCallback() {
public final void onCompleted(final GraphUser user, final Response response) {
currentUser = user; // currentUser is defined as a class member
if (response.getError() != null ) {
// TODO
}
}
});
requestCurrentUserProfile.executeAsync();
} else
this.currentUser = null;
}
使用调试器在这里放置一个断点,GraphUser表示就完成了:我拥有了我需要的所有数据,包括位置!
关于最终用户的好友列表...
public final void fetchFriendsList() {
if (this.session != null && this.session.isOpened()) {
final Request requestUserFriendsList = Request.newMyFriendsRequest(
this.session, new Request.GraphUserListCallback() {
public final void onCompleted(final List<GraphUser> users, final Response response) {
if (users != null && users.size() > 0)
userFriendsList = new ArrayList<GraphUser>(users);
}
}
);
requestUserFriendsList.executeAsync();
}
}
用户几乎是空的,这里只是一个名称和一个ID。 就是这样,仅此而已。
请问这个Request
没有提供更多数据吗?
如果是这样,我应该使用哪种方法来获取所需的数据?
谢谢 !
[编辑]
查看我的应用程序审查状态,我什至都不愿收回朋友列表或当前最终用户的位置数据? !
这是怎么回事? 我不明白...请帮助!
[EDIT2]
为了向您展示最终用户GraphUser和最终用户朋友列表GraphUsers之间的区别,这是调试器的屏幕截图。 出于隐私原因,我们已故意删除了这些字段。
当询问朋友的数据时,您可能必须在request参数中显式请求这些字段。
像这样,
private void makeMyFriendsRequest(final Session session) {
Request request = Request.newMyFriendsRequest(session, new Request.GraphUserListCallback() {
@Override
public void onCompleted(List<GraphUser> users, Response response) {
// If the response is successful
if (session == Session.getActiveSession()) {
for (GraphUser user : users) {
System.out.println(user.getFirstName() + " " + user.getLastName());
System.out.println(users.get(i).getId());
GraphLocation loc = users.get(i).getLocation();
System.out.println(loc != null ? loc.getCity() : "loc not available");
}
}
}
});
// here add fields explicitly
Bundle bundle = request.getParameters();
bundle.putString("fields", "id,first_name,last_name,birthday,location");
request.executeAsync();
我希望这将有所帮助。
PS:我假设您正在使用这样的登录按钮来请求权限,
loginButton.setReadPermissions(Arrays.asList("user_location", "friends_location"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.