Reputation: 32986
I'm experimenting with making a Facebook web app. What I want to do is have one of those popup dialogs that let you select from all your friends. The user selects some friends, and when they click OK, the IDs of the friends select get stored into a Javascript array.
It looks like I could use FB.ui, but the examples I've seen are all requests, like posting on a wall or inviting someone to a page. I just want to load those IDs into an array. How can this be done?
Upvotes: 1
Views: 1577
Reputation: 25918
You can use something like jQuery Facebook Multi-Friend Selector or implement it yourself using response from friends
connection of user
as source for data.
FB.ui
isn't really going to help you since it's not providing a way of displaying users in a UI that you wish for functionality other than Requests.
If you're going with jQuery Facebook Multi-Friend Selector it's as simple as adding <div id="jfmfs-container"></div>
to your page and using next JavaScript:
$("#jfmfs-container").jfmfs();
$("#jfmfs-container").bind("jfmfs.selection.changed", function(e, data) {
// `data` is Array of objects like {id: USER_ID, name: USER_NAME}
console.log("changed", data);
// `userIds` is the array of users ids
var userIds = $(this).data('jfmfs').getSelectedIds();
});
Upvotes: 3
Reputation: 11375
The Facebook Graph API lets you get a list of a user's friends, and you can use those ids in an array:
http://developers.facebook.com/docs/reference/api/user/#friends
Read
You can read the list of a User's friends by issuing an HTTP GET to /PROFILE_ID/friends with any valid access_token of the current session user. For example:
Upvotes: 1