Facebook <fbml:ref../>

Date October 3, 2007 @ 1:14 pm in Open Source, PHP

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

7 Responses to “Facebook <fbml:ref../>”

  1. Mark Otero said:

    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

  2. joel said:

    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.

  3. Ben said:

    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

  4. jeny said:

    Hi ,

    What should i pass this $rssItems.

  5. jeny said:

    Hi ,

    What should i pass this $rssItems.and can u plz explain this detaily.

  6. Basic Facebook App Architecture - Day Day Up! said:

    [...] FBML to the profile asynchronously, which is accomplished using fb:ref(see related forum post and blog post). That FBML can have Flash which can dynamically pull from the app server, and there are other ways [...]

  7. LWord said:

    Hi all,
    Can one help me in writing FBML + PHP program. FBML is not working for me.

    Thanks

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">