Although we haven't gone through all the FBML tags, you should now be able to continue exploring the usage of other FBML tags on your own. Now, let's move to the next level - enhancing our 1st Facebook Application.

Do you remember other than FBML, what Facebook has provided us to write our 1st Facebook App?

Yes, it's the client library! To recap, we are the "older" PHP client library (which is also referred as the "Old Rest API Client Library"). In the section, we will learn how to publish a post onto the user's wall by using this client library.


Sample Post in User's Wall

Let's take a look at the post that we are going to publish to the user's wall from our application:

Note that we are going to set the following information in our post:


How to Publish Post by using the Old PHP Client Library

For testing purpose, we can develop a page so that the user accesses it, a post will be published to the user's wall and display a confirmation message. The code is listed below:


   require_once 'lib/facebook.php';
   require_once 'config.php';
   $facebook = new Facebook($appapikey, $appsecret);
   $user_id = $facebook->require_login("publish_stream");
   include 'dashboard.php';
   include 'tabs.php';
   $attachment = array('name' => 'This is my demo Facebook application!',
                       'href' => '',
                       'description' => 'It is fun!',
                       'media'=> array(array(
                                      'type'=> 'image',
                                      'src' => '',
                                      'href' => ''))
   $action_links = array(array('text' => 'Start Learning', 
                               'href' => '') );
   $facebook->api_client->stream_publish('is learning how to develope Facebook apps.', 
                                         $attachment, $action_links);

<h3>A post had just been published into the stream on your wall. </h3>


The stream_publish method

The signature of the stream_publish method in the client library is also a good reference. It is defined in the facebookapi_php5_rest.php (which is included within the client library) as:

 * Publish a post to the user's stream.
 * @param $message        the user's message
 * @param $attachment     the post's attachment (optional)
 * @param $action links   the post's action links (optional)
 * @param $target_id      the user on whose wall the post will be posted
 *                        (optional)
 * @param $uid            the actor (defaults to session user)
 * @return string the post id
 public function stream_publish(
    $message, $attachment = null, $action_links = null, $target_id = null,
    $uid = null) {

 return $this->call_method(
   array('message' => $message,
   'attachment' => $attachment,
   'action_links' => $action_links,
   'target_id' => $target_id,
   'uid' => $this->get_uid($uid)));