Facebook <fbml:ref../>
For those of you who have embarked on writing a Facebook app, you may have faced the challenge of how to automatically update your profile fbml without forcing a user to take action. The approach I have found most effective is to use the <fbml:ref> tag. Facebook defines this command as a tag which “fetches and renders FBML from a given ref source – either a ref string “handle” you’ve created using fbml.setRefHandle or a URL that serves FBML. ” When using “fbml.setRefHandle” Facebook stores this FBML on its servers in the form of a hashtable. Using a single push we can update FBML for all users that have our application installed.
For a recent client we were asked to display the first few entries from a RSS feed within a users profile. All Facebook users would see the same entries, until the RSS feed changed. Here is the PHP we used to set a users FBML.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function render_ref_fbml($uid, $rssItems) { global $facebook; try { // Set FBML Cache $refFbml = render_narrow_fbml($id, $rssItems); $refFbml .= render_wide_fbml($id, $rssItems); $facebook->api_client->fbml_setRefHandle('RssFbml',$refFbml); // Set Profile FBML $fbml = render_css_style(); $fbml .= '<fb:ref handle="RssFbml">'; $facebook->api_client->profile_setFBML($fbml, $uid); } catch (Exception $e) { error_log($e->getMessage()); } } |
In a standalone php file we then created a similar function which updated only the FBML stored under the “RssFbml” handle.
1 2 3 4 5 6 7 8 9 10 11 | function render_ref($rssItems) { global $facebook; try { // Set FBML Cache $refFbml = render_narrow_fbml(0, $rssItems); $refFbml .= render_wide_fbml(0, $rssItems); $facebook->api_client->fbml_setRefHandle('RssFbml',$refFbml); } catch (Exception $e) { error_log($e->getMessage()); } } |
This php file uses an infinite Facebook session and is called every 30 min by a CRON job.
1 | 30 * * * * php -f /var/www/rss.php |


3 Comments so far >>
What ids get passed the functions render_narrow_fbml and render_wide_fbml? In your second example, no Ids get passed, why is that? Thanks! - Mark
By Mark Otero on 11.20.07 3:20 pm
Mark,
Both of those functions are used internally to build up my FBML strings. The intent of the first argument of “render_xxx_fbml” was to be the Facebook userid of the current user. In my situation neither were allowed in my FBML since the majority of FBML was set globally for all users.
By joel on 11.21.07 6:21 am
Thanks for laying this out! I’m looking to use this for getting an RSS entry on profile pages as well.
Are you using infinite sessions? http://developers.facebook.com/documentation.php?doc=auth
By Ben on 04.29.08 8:18 pm
Leave a comment