Facebook Application Development – Publishing to the Wall

September 24th, 2011 by laeeq | No comments

Its very easy to publish stream via Facebook,  let’s post something to the wall after verifying the user has the publish_stream permission

  1. # let’s check if the user has granted access to posting in the wall
  2. $api_call = array(
  3. ‘method’ => ‘users.hasAppPermission’,
  4. ‘uid’ => $uid,
  5. ‘ext_perm’ => ‘publish_stream’
  6. );
  7. $can_post = $facebook->api($api_call);
  8. if($can_post){
  9. # post it!
  10. $facebook->api(‘/’.$uid.‘/feed’, ‘post’, array(‘message’ => ‘Saying hello from my Facebook app!’));
  11. echo ‘Posted!’;
  12. else {
  13. die(‘Permissions required!’);
  14. }

Essentially, we are making an API call to //feed, using the POST method (second argument) and an array as a third argument for the data to be sent. In this case, this third argument supports message, link, picture, caption, name and description. Here’s the code:

  1. $facebook->api(‘/’.$uid.‘/feed’, ‘post’, array(
  2. ‘message’ => ‘The message’,
  3. ‘name’ => ‘The name’,
  4. ‘description’ => ‘The description’,
  5. ‘caption’ => ‘The caption’,
  6. ‘picture’ => ‘http://i.imgur.com/yx3q2.png’,
  7. ‘link’ => ‘http://net.tutsplus.com/’
  8. ));

Here’s how it is posted.

You can subscribe to PHPZAG.COM posts by Email

 

Related Topics:

  • Facebook Application Development
  • Facebook Application Development – Facebook Authentication
  • Facebook Application Development – Extend Permissions
  •  

     

    1. No comments yet.
    1. No trackbacks yet.