thoughtlabs

A brief example of how to use fb:ref on Facebook or sn:ref on Bebo

Written by John Maver  ()
on May 6, 2008 ·

Facebook-Developer

fb:ref is a way to set a placeholder on a bunch of user profiles, and then update it across all those profiles with a single call. It makes sense to use when you have data or images that would need to be updated occasionally, but are not specific to the current viewing user. Some examples would be banner, application news updates, or perhaps an entire theme for a profile box.

You can have multiple fb:ref's - they are keyed off the one of two things:

  1. A callback url. In this case, you use the <fb:ref> to place the block, and the fbml_refreshRefUrl() to update it.
  2. A handle name. In this case, you use <fb:ref> to place the block, and fbml_setRefHandle() to update it.

Below, I will show steps for implementing the callback method:

  1. Set users' profiles with code like this:
      $fbml = "&lt;fb:ref url='http://yourserver.com/callbackurl' /&gt;";
      $facebook->api_client->profile_setFBML("", NULL, $fbml, "", "");
    

    on Bebo it would be:

      $snml = "&lt;sn:ref url='http://yourserver.com/callbackurl' /&gt;";
      $bebo->api_client->profile_setSNML($snml , $userid);
    

    For the callback url, you can either use a unique page or just pass a GET parameter that you can check for later like this:

      &lt;fb:ref url='http://yourserver.com/yourapp/callbackurl/?refcallback=1' /&gt;
    
  2. In the callback page, add some code the detects that it is the refresh, and updates the ref block:
      if ( isset($_GET['refcallback']) ) {
        $text = "
          &lt;div&gt;
            &lt;img src='http://yourserver.com/yourapp/someimage.jpg'/&gt;
          &lt;/div&gt;
        ";
        echo $text;
      }
    
  3. When you want to update the ref in all the profiles, call:
      $refreshURL = "whatever you used for the sn:ref above";
      $facebook->api_client->fbml_refreshRefUrl("$refreshURL");
     

    on Bebo it would be:

       $refreshURL = "whatever you used for the sn:ref above";
       $bebo->api_client->snml_refreshRefUrl("$refreshURL");
     

Topics: Programming

Sign up for our Fresh Thoughts Newsletter

Follow us:

Get Articles via Email

Enjoy this article? Don't forget to share.