简体   繁体   中英

Publish to a friend's wall using Facebook API

I know we can publish something on a friend's wall with this:

$publishStream = $facebook->api("/$user/feed", 'post', array(
     'message' => "Your Message", 
     'link'    => 'http://example.com',
     'picture' => '',
     'name'    => 'App Name',
     'description'=> 'App description'
));

Just by replacing the $user variable with the user id of your friend.

What i wish is simply to choose among my friends, the user profiles i want to write on using check boxes.

this is something already possible if you want to share a fan page for instance. You choose the persons you send the request to.

Thanks in advance for your help

You can use Facebook's Multi-Friend-Selector (MFS) . https://developers.facebook.com/docs/guides/games/custom-muti-friend-selector/

An edited example taken from the Multi-Friend-Selector documentation

function renderMFS() {
 // First get the list of friends for this user with the Graph API
 FB.api('/me/friends', function(response) {
   var container = document.getElementById('mfs');
   var mfsForm = document.createElement('form');
   mfsForm.id = 'mfsForm';

   // Iterate through the array of friends object and create a checkbox for each one.
   for(var i = 0; i < Math.min(response.data.length, 10); i++) {
     var friendItem = document.createElement('div');
     friendItem.id = 'friend_' + response.data[i].id;
     friendItem.innerHTML = '<input type="checkbox" name="friends" value="'
       + response.data[i].id
       + '" />' + response.data[i].name;
       mfsForm.appendChild(friendItem);
     }
     container.appendChild(mfsForm);

     // Extract selected friends' Facebook ID from value property of checked checkboxes

     // Do a for loop to send notification (refer to the link posted below) and publish post to each user's wall
   });
 }

And is it possible to send notifications before the messages are written on the walls?

Yes it is possible when you have the Facebook ID. Refer to my answer in How to send Facebook message to friend using Facebook ID?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM