Publishing user actions to their wall is one of the basic functionalities that make one application viral in the Facebook world. So i’ll present here a simple method for dynamic retrieval of feed data. My example includes FBML, JavaScript, FBJS, PHP.
Quick links: FB Feed, FBJS AJAX, Feed Template Console,
Instead of storing the feed data for every action that the user can publish to his wall we can create interface (in php file) for retreaving the feed data. First in the FBML of the application we have to define our JavaScript function:
in index.php:
function toWall(feed_id, feed_url){
var toWalldialog = new Dialog();
var ajax = new Ajax();
ajax.responseType = Ajax.JSON;
ajax.requireLogin = true;
ajax.ondone = function(data){
toWalldialog.hide();
Facebook.showFeedDialog(feed_id, data);
};
toWalldialog.showMessage("Loading feed data", loading_image);
ajax.post(feed_url);
}
I’m using here in this function a predefined variable loading_image, for which Facebook takes care:
in index.php:
<fb:js-string var="loading_image">
<p style="text-align:center;">
<img src="http://daniel-zahariev.info/img/indicator.gif" alt="" />
</p>
</fb:js-string>
Then we have to call it:
in index.php:
<a onclick="toWall(feed_id, 'link-to/interface.php'); return false;" href="#">publish to wall</a>
In the php file we can have something like this:
in interface.php:
<?php
include "facebook.php";
$feed_data = array("set here the value of all keys that you should provide to the registered feed");
echo jdon_encode($feed_data);
?>
It is fairly simple method to make your FBML output lighter and this way you make your application faster.
Facebook, FBJS