updating profile box using <fb:ref />
<fb:ref is a new fbml tag used to store data and later re-use it. there are two types of ref handler, one is static and another is url based. lets have a look at their structure
1. string handle which just stores FBML and later output the content – like
<fb:ref handle="application_specific_unique_handle" />
or
2. url based, which must serve valid FBML
<fb:ref url="some_url" />
you can create <fb:ref /> by using fbml_setRefHandle() function. now lets see <fb:ref />s in action. the following code will create a <fb:ref /> and you can later use it anywhere in your application. remember, once created the ref objects are in application scope. and until you change the content again using fbml_setRefHandle() api, it will remain the same.
<?php
include "config.php";
$handle = "greetings";
$markup = "Hello <fb:name uid='{$uid}' /> ";
$facebook->api_client->fbml_setRefHandle($handle, $markup);
?>
now you can use it anywhere in your application like this
<fb:ref handle="greetings" />
it will say "Hello <User’s Name>"
but wait, there is a major disadvantage with this type of handlers and that is the content of this ref object is cached. say, while creating the ref object if the $uid was, for example 503274632 (which is my id) – when I will come to a page that used this "greetings" ref object, I will see that the out put is "Hello you" and that is expected. Now when another user see the same page he will see that the output is "Hello Hasin Hayder", but this was not expected. Look, here it didn’t update the content according to the new user. Because the content of this ref object will remain cached until u change it again using fbml_setRefHandle() api.
to over come this problem and to make these ref objects more usable, you can use url type ref objects. lets see below, you have to use fbml_refreshRefUrl() api.
<?php
include "config.php";
$url = "http://sandbox.ofhas.in/fbtest/ru.php?uid={$uid}";
$facebook->api_client->fbml_refreshRefUrl($url);
?>
and the content of ru.php is
Hello from an external Url <fb:name uid="<?=$_REQUEST['uid'];?>" useyou="false" />
now you can use this url type ref object anywhere in your application, like this
Greetings! <fb:ref url="<?=$url;?>" />
now if you want to update content of your user’s profile box offline. Just print any url type ref handler in his profile box using profile_setFBML() api. later, on the time of updating all you have to do is call fbml_refreshRefUrl() so that facebook re cache the content of this url. and regardless to say that your url will deliver all the updated content to display on yoru profiles. your url will always get the user id via “uid” parameter in HTTP GET, so you can decide easily what to deliver.
if you are still confused or have any question, don’t forget to write it as a comment. in next article I am coming with “how to successfully keep record of all the users of your applications and how to remove them successfully when they remove your app” – stay tuned.



