How to get userids of Facebook friends from Friend Selector dialog box

Recently I was developing a Facebook app for a client which requires to invite user friends. For this I used the FB.ui apprequests method. I also need to get the user ids of Facebook friends the user has invited. My initial approach was to print the response of the apprequests method, but it gave undefined object error. Here is what I tried initially and that didn’t return the userids.

FB.ui({ method: 'apprequests',message: 'Some message'}, function(res){
echo res; //echo res.error;  echo res.description;

But it was quite clear that this is not the right way. After some searching I got it right. I am sharing so that somebody else can use it.

FB.ui({ method: 'apprequests',message: 'Some message'}, function(res){
        	var req_ids = res.request_ids;
    		var _batch = [];
    		for(var i=0; i<req_ids.length; i++ ){
            		var IDs='';
        		for (var j = 0; j<res.length; j++) {
                       		body = res[j].body;
                                var myObject = eval('(' + body + ')');
                                friendID =; 
                                echo friendID;  //one friend id

Hope now that you can get Facebook friends userids from the friend selector dialog box. In the future post I will be discussing how these userids can be used in our app to send Facebook Events invite to users friends.

Tags: , , ,

1 Response to "How to get userids of Facebook friends from Friend Selector dialog box"

  • ers says:
Leave a Comment