1
我需要獲取用戶選擇的朋友的朋友詳細信息。Facebook SDK - 獲取朋友詳細信息
用戶可以使用默認facebook朋友選擇器來選擇他的朋友。但是當我將選擇作爲GraphUser的列表時,我看不到任何用戶的細節。特別是,我無法獲取用戶名。
這裏是朋友選擇器的活動:
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);
}
}
當我嘗試讀取用戶名列表中,我總是空。
在此先感謝。
這行代碼
檢查setExtraFields方法嗨 我加入setExtraFields但選擇沒有得到值來完成 –