Bob-ob
Bob-ob

Reputation: 1618

Facebook API (Javascript): Posting to a friendlist

Can someone point me in the right direction for publishing a post to a friendlist using the Facebook JS API? I have so far been using this code:

    FB.api('me/feed', 'post', { message: msg,privacy: {value: "CUSTOM", friends: "SOME_FRIENDS", allow:selected_list}}, function(response) {
        if (!response || response.error) {
            console.log(response);
            console.log('ERROR ERROR ERROR');
        }
        else {
            console.log(response);
            console.log('successfully sent, now reload data');
            refreshData();
        }
    })

In this case, *selected_list* is the id for the friend list. I have also tried passing in a list of ids to post to my friends walls using a string like this: "aID,bID,c_ID,d_ID"

It seems to be posting to my own wall but not to my friends walls and more important does not show up in the friendlist feed. I can post comments on a feed easily but can't create new posts and have them shared among my friends within that list.

Any help would be greatly appreciated.

Upvotes: 0

Views: 357

Answers (2)

Andrew
Andrew

Reputation: 61

Your using the deprecated format for the privacy object. I suspect that is your issue.

FB.api('/me/feed', 'post', { 'message': msg, 'privacy' : {'value': 'CUSTOM',
      'allow':'uid1,uid2,flid1,flid2'}}, function(response) {

    }
});

And don't try to use spaces in your comma separated list. I spent 3 hours before figuring out that you can't do that.

Upvotes: 1

Usha
Usha

Reputation: 1468

The code you wrote posts to your own wall.. The API is posting to me/feed which is nothing but your own wall.. It should be FRIEND_ID/feed

FB.api('/FRIEND_ID/feed', 'post', { message: body }, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response.id);
  }
});

The above code posts the message to the friend's wall with the FRIEND_ID. Hope this helps.

Upvotes: 1

Related Questions