0

**HI i am trying to send app request to 30 random friends of the user. So i want to get user ids of 30 facebook friends parse it and feed the uids into

function sendRequestToRecipients() {
var user_ids = document.getElementsByName("user_ids")[0].value;
FB.ui({method: 'apprequests',
message: 'sample message',
to: 'id of friend1,id of friend2,id of friend 3,,,,,,,'
}, requestCallback);
}**

Below is the full sample code...

 

<script>
  FB.init({
    appId  : 'appid',
    frictionlessRequests: true,
  });

we have to put ids of friend here.....

  function sendRequestToRecipients() {
    var user_ids = document.getElementsByName("user_ids")[0].value;
    FB.ui({method: 'apprequests',
      message: 'sample message',
       to: 'id of friend,id of friend'
    }, requestCallback);
  }

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

  function requestCallback(response) {
    // Handle callback here
  }
 </script>
Ramanvir Sodhi
  • 161
  • 1
  • 9
  • 1
    [What have you tried](http://www.whathaveyoutried.com/) and what is the issue you are facing? – Howard May 28 '12 at 17:33
  • i am unable to get uids of random 30 friends and feed them to FB.ui({method: 'apprequests', message: 'sample message', to: 'id of friend1,id of friend2,id of friend 3,,,,,,,' }, requestCallback); }** – Ramanvir Sodhi May 28 '12 at 17:41

1 Answers1

0
FB.api({ method: 'friends.get' }, function(result) { 
       var user_ids="" ;
       var totalFriends = result.length;
       var randNo = Math.floor(Math.random() * totalFriends);
       var numFriends = result ? Math.min(30,totalFriends) : 0;
       if (numFriends > 0) {
          for (var i=0; i<numFriends; i++) { 
            user_ids+= (',' + result[randNo]);
            randNo ++;
            if(randNo >= totalFriends){
                randNo = 0;
            } 
          }
        }
        profilePicsDiv.innerHTML = user_ids;
    alert(user_ids);

      });

Refer my answer at Facebook App invitation request

Community
  • 1
  • 1
Jashwant
  • 28,410
  • 16
  • 70
  • 105