Take the 2-minute tour ×

I need to get 50 random Facebook friends and assign the result to this variable user_ids used in this function sendRequestToRecipients(). What I want to do is like in this example:

All examples on Stack Overflow are not working, I need some help to make this function working.

Here is my code:


      <input type="button"
        onclick="sendRequestToRecipients();return false;"
        value="Send Request to Users Directly"/>

    <input type="button"
      onclick="sendRequestViaMultiFriendSelector(); return false;"
      value="Send Request to Many Users with MFS"

        appId  : '398994226827517',
        status : true,
        oauth  : true,
        Xfbml  : true,
        cookie : true,
        frictionlessRequests : true

   function sendRequestToRecipients() {
    FB.ui({method: 'apprequests',
      message: 'sample message',
       to: 'user_ids'
    }, requestCallback);

  function sendRequestViaMultiFriendSelector() {
    FB.ui({method: 'apprequests',
      message: 'sample message'
    }, requestCallback);

  function requestCallback(response) {
    // Handle callback here

share|improve this question

4 Answers 4

up vote 0 down vote accepted

As previously mentionned, this is really annoying for the user, as he can't select his friends.

If you really want to do that, this should work :

FB.api('/me/friends', function(friend) {
  FB.ui({method: 'apprequests',
    message: 'Random Friends',
    to: 'friend[0].id,friend[1].id,friend[2].id'
  }, requestCallback);

It will select the first 3 friends (not random but better).

share|improve this answer
Facebook updated its platform policy so that apps may not offer a select all option or pre-select multiple recipients to receive requests. Facebook will remove the ability to "Select All" or "Pre-Select" for Requests starting on January 8, 2014. –  gparis Jul 15 '13 at 11:27

approved message need some changes like following

    var user_ids = [];
    $(friend.data).each(function(index, element) {
  FB.ui({method: 'apprequests',
    message: 'sample message'
    to: user_ids
share|improve this answer

Why would ANYONE want to invite random friends to an app? Your app could quickly be shut down for spam if you do this. Let the users choose who they want to invite to the app, don't try to force them to spam random friends who may have no interest in the app.

If you really must do this, you can, according to the Requests Dialog documentation prefill the 'to' parameter with the uids of the users you want your app's user to send the requests to, the example in the docs is:

function sendRequestToRecipients() {
  FB.ui({method: 'apprequests',
    message: 'My Great Request',
    to: '499802820,499802852'
  }, requestCallback);
share|improve this answer
I saw a lot of apps like this that are runnig for a long time ,I know that this is a bit spammy but Igy you have right in long term is not a good solution .thanks –  Gabriel Bora Aug 20 '12 at 19:03


 $fql = "SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) order by rand() limit 20";

 $response = $facebook->api(array(
     'method' => 'fql.query',
     'query' =>$fql,
 $ids = "";
   $ids .= $c.$value['uid'];
 } ?> 


    method       : 'apprequests',
    title        : '<?php echo $app->title;?>',
    message      : "<?php echo $app->img_description;?>",
    to: "<?php echo $ids;?>"
}, function (data) {});
share|improve this answer

Your Answer


