0

I have this code:

       function graphStreamPublish(){


var params = {};
params['message'] = '';
params['name'] = '';
params['description'] = '';
params['link'] = '';
params['picture'] = '';
params['caption'] = '';

FB.api('/me/feed',  'post', params, function(response) {
  if (!response || response.error) {
   alert('Error occured');
  } else { }

which works awesome and it posts to my wall or my friend's wall when I change /me/feed to /MY_FRIENDS_ID/feed

But what I want is to post to 25 friends at a time (with one click) by randomly selecting my friends IDs .

Is there any PHP code or anything that can do that? For example accessing and extracting my friends IDs to a some kind of file and then putting them in to the /FRIENDS_ID/feed code?

Sorry for my english. I just started to learn facebook apps yesterday, sorry if I sound too amateur.

I heard there is some php code called 'loop' and it works... Please if anyone can help me. I would appreciate that!

Jag
  • 1
  • 1
  • 2
  • Well, actually you answered your question to be honest. If you need help with PHP then probably you'll be better off posting the question in the PHP section. The Graph API call in case of PHP is the same as the one you're using - for convenience you may want to use the SDK https://github.com/facebook/php-sdk/ – Bartek Jan 24 '11 at 19:31
  • Bartek, thanks for the answer, but this ain't helping me much :( My all code is in JavaScript SDK and it's in my index.html file. What I like to know is can I somehow manipulate FRIEND_ID code line: '/FRIEND_ID/feed' by adding a php variable instead of one ID and randomly and automatically select my 25 friends IDs and POST. I have found 2 ways of getting my friend list to show by using FB.api('/me/friends' and FB.api({ method: 'friends.get' }, Maybe there is any way of combining these two together? Getting friends ID's and get them in the '/FRIEND_ID/feed' line? Hope I'm clear now. – Jag Jan 24 '11 at 21:42

1 Answers1

0

First, you can get all friends IDs using the API. You can then select 25 random indices from that array.

Here is an example of how to do it: Getting a random value from a JavaScript array

You can then iterate through the (randomly) selected indices, and for each iteration, you can do the FB.api call.

The graphStreamPublish could take one parameter, which is the ID of the person whose wall you want to post to, so it could look something like this:

function graphStreamPublish(targetID) {

    var params = {};
    params['message'] = '';
    params['name'] = '';
    params['description'] = '';
    params['link'] = '';
    params['picture'] = '';
    params['caption'] = '';

    FB.api('/' + targetID +'/feed',  'post', params, function(response) {
        if (!response || response.error) {
            alert('Error occured');
        } else {});

Also, I'm thinking the params object can also be sent as a parameter.

And finally, here's how this function would look in the mentioned context:

for(i = 0; i < selectedFriendIDs.length; i++)
    graphStreamPublish(selectedFriendIDs[i]);

Hope this helps. Have a great day!

Community
  • 1
  • 1
Romi Halasz
  • 1,949
  • 1
  • 13
  • 23