0

I want to send my Application invites to multiple random people in my friends list just as its done in majority of application. For Instance enter image description here

As soon as i Accept the application this pop up appears.What i cannot understand is how to get the ID's of these users ? On the Client Side ?

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:fb="https://www.facebook.com/2008/fbml">
  <head>
    <title>Request Example</title>
  </head>

  <body>
    <div id="fb-root"></div>
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <p>
      <input type="button"
        onclick="sendRequestToRecipients(); return false;"
        value="Send Request to Users Directly"
      />
      <input type="text" value="User ID" name="user_ids" />
      </p>
    <p>
    <input type="button"
      onclick="sendRequestViaMultiFriendSelector(); return false;"
      value="Send Request to Many Users with MFS"
    />
    </p>

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

      function sendRequestToRecipients() {
        var user_ids = document.getElementsByName("user_ids")[0].value;
        FB.ui({method: 'apprequests',
          message: 'My Great Request',
          to: user_ids,                        ///  How to Fill the ID's HERE ?
        }, requestCallback);
      }

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

      function requestCallback(response) {
        // Handle callback here
      }
    </script>
  </body>
</html>
Yahoo
  • 4,093
  • 17
  • 59
  • 85

1 Answers1

1

Why would you want to send to random users? That doesn't make any sense - surely you'd invite the people you think will like the game?!

Confusion aside, to answer your question, the 'to' parameter is either an array, or a comma seperated list of user IDs.

Here's an example of CSV, taken from the documentation:

function sendRequestToRecipients() {
  FB.ui({method: 'apprequests',
    message: 'My Great Request',
    to: '499802820,499802852'
  }, requestCallback);
}
Igy
  • 43,710
  • 8
  • 89
  • 115
  • -` FB.api('/me/friends', function(response) { The Response has a list of ID's and Names , Now how can i extract random ID's and pass it to the sendRequestToRecipients() });` – Yahoo May 23 '12 at 18:47
  • By randomising the results; finding out how to do this should take a few seconds with Google – Igy May 23 '12 at 18:47
  • I tried it but it returned some complicated Fisher-Yates algorithm for randomising the response . – Yahoo May 23 '12 at 19:09
  • Does this not work? //Randomize the order of the array: `var myarray=[25, 8, "George", "John"] myarray.sort(function() {return 0.5 - Math.random()}) //Array elements now scrambled` – Igy May 23 '12 at 19:12
  • FB.api('/me/friends', function(response) { var myarray=response ; myarray.sort(function() {return 0.5 - Math.random()}) document.getElementsByName("user_ids")[0].html = response ; console.log('Good to see you, ' + myarray + '.'); Is giving me Uncaught TypeError: Object # has no method 'sort' – Yahoo May 23 '12 at 19:20
  • One more question . How do you Format the Code here in Comments ? CTRL + k ? – Yahoo May 23 '12 at 19:21
  • If they're still in the Object structure, load the user IDs into an array and sort that instead – Igy May 23 '12 at 19:22
  • I am not sure how thats done ? var myarray = eval ("(" + response + ")"); ? – Yahoo May 23 '12 at 19:30
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11657/discussion-between-adi-mathur-and-igy) – Yahoo May 23 '12 at 19:32