2014-02-28 264 views
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); 
} 
} 

當我嘗試讀取用戶名列表中,我總是空。

在此先感謝。

回答

1

當您使用basic_info權限(這是默認權限)查詢好友列表時,您只能獲取id和名稱字段。爲了獲取用戶名字段,您必須將其添加爲您的friendPickerFragment的額外字段。

它可以簡單地通過增加對相關文件here

+0

這行代碼

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

檢查setExtraFields方法嗨 我加入setExtraFields但選擇沒有得到值來完成 –

相關問題