I was searching for methods to select multiple friends for facebook and came to know a javascript plugin made by keeganstreet. Using this plugin for your facebook app is very simple. Download source code and add your app id in example.js to test.

Including tdfriendselector.js is necessary and if you want to use default interface include the tdfriendselector.css stylesheet in your document. Use whole TDFriendSelector div from index.html as it is if you want to use default interface.
First of all, you have to initialize the plugin.
TDFriendSelector.init({debug: true});
Following code will create friend selector instance. You can create multiple instances per page.
selector = TDFriendSelector.newInstance({
callbackFriendSelected : callbackFriendSelected,
callbackFriendUnselected : callbackFriendUnselected,
callbackMaxSelection : callbackMaxSelection,
callbackSubmit : callbackSubmit,
maxSelection : 1,
friendsPerPage : 5,
autoDeselection : true
});
To bind a button with selector to show interface, use following code.
$("#btnSelect").click(function (e) {
e.preventDefault();
selector.showFriendSelector();
});
Following code will print selected friends. logActivity is the function to print output .
callbackFriendSelected = function(friendId) {
var friend, name;
friend = TDFriendSelector.getFriendById(friendId);
name = friend.name;
logActivity('Selected ' + name + ' (ID: ' + friendId + ')');
};
The friends are returned as an array of Facebook IDs.
About Pawan Maurya
Pursuing B.Tech in Computer Science and Engineering. Passionate about technology and blogging .
- Web |
- More Posts (27)