gpt4 book ai didi

android - Facebook SDK - 获取好友详情

转载 作者:行者123 更新时间:2023-11-30 03:04:13 27 4
gpt4 key购买 nike

我需要获取用户选择的好友的好友详情。

用户可以使用默认的 facebook 好友选择器来选择他的好友。但是当我将选择作为 GraphUser 列表时,我看不到用户的任何详细信息。特别是,我无法获取用户名。

这是好友选择器的 Activity :

public class FacebookFriendPickerActivity extends FragmentActivity {

public static final String IEXTRA_SELECTED_FRIENDS = "selected friends";

private FriendPickerFragment friendPickerFragment;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facebook_frind_picker);

Bundle args = getIntent().getExtras();
FragmentManager manager = getSupportFragmentManager();
Fragment fragmentToShow = null;

if (savedInstanceState == null) {
friendPickerFragment = new FriendPickerFragment(args);
} else {
friendPickerFragment = (FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment);
}
// Set the listener to handle errors
friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
@Override
public void onError(PickerFragment<?> fragment, FacebookException error) {
Toast.makeText(FacebookFriendPickerActivity.this, error.getLocalizedMessage(), Toast.LENGTH_LONG).show();
setResult(RESULT_CANCELED);
finish();
}
});
// Set the listener to handle button clicks
friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
@Override
public void onDoneButtonClicked(PickerFragment<?> fragment) {
List<GraphUser> users = friendPickerFragment.getSelection();
if (users.size() > 0) {
ArrayList<String> usernames = new ArrayList<String>(users.size());
for (GraphUser user : users)
usernames.add(user.getUsername());
Intent data = new Intent();
data.putStringArrayListExtra(IEXTRA_SELECTED_FRIENDS, usernames);
setResult(RESULT_OK, data);
finish();
} else {
setResult(RESULT_CANCELED);
finish();
}
}
});
fragmentToShow = friendPickerFragment;
manager.beginTransaction().replace(R.id.picker_fragment, fragmentToShow).commit();
}

@Override
protected void onStart() {
super.onStart();
friendPickerFragment.loadData(false);
}
}

当我尝试读取用户名列表时,我总是得到 null。

提前致谢。

最佳答案

当您使用 basic_info 权限(默认权限)查询好友列表时,您只会获得 id 和 name 字段。为了获得用户名字段,您必须将其作为额外字段添加到您的 friendPickerFragment。

只需添加这行代码即可完成

friendPickerFragment.setExtraFields(Arrays.asList("username"));

查看相关文档中的setExtraFields方法here

关于android - Facebook SDK - 获取好友详情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22089774/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com