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.
11 Responses to “updating profile box using <fb:ref />”
Leave a Reply



























lenin on February 4th, 2009
Cool
ranacse05 on February 4th, 2009
thanks for publish this topic . I need this very much .
bijon on February 4th, 2009
very much helpful for learning fb application.Good to see join others open source enthusiast.
ranacse05 on February 5th, 2009
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.
one example please .
ranacse05 on February 5th, 2009
I think u forgot to tell about this http://wiki.developers.facebook.com/index.php/Extended_permissions
Hasin Hayder on February 5th, 2009
we will write an article on Extended Permissions in near future.
rc29 on February 11th, 2009
Hi Hasin,
i have a question… i have an auto update file that is called by a cron, and this file should modify either the profile or the status. But it seems that i have a problem. In fact it works when i called the file manually with the url, but not with the cron. I supposed it’s related to the FB session.
here is the code:
set_user($user, $appsession);
// script that does the jov via the API
}
mysql_close();
?>
Do you have an idea ? it would great if you had time to give me your point of view !
Thanks a lot ! Bye
rc29 on February 11th, 2009
Oooops ! Seems that i can’t put all the code, … new try:
require_once ‘lib-facebook/facebook.php’;
require_once ‘appconf.php’;
require_once ‘appinclude.php’;
$GLOBALS['facebook_config']['debug'] = false;
$appsession = ‘xxxxxxxxxx’;
$facebook = new Facebook($appapikey, $appsecret, $appsession);
mysql_connect($host, $dbuser, $dbpassword);
mysql_select_db($database) or die( “Unable to select database”);
$users = user_list (); // array id users
foreach ($users as $user)
{
$facebook->set_user($user, $appsession);
// script that does the jov via the API
}
mysql_close();
Edwin on March 19th, 2009
Hey,
when I try your example code it just shows up as “Greetings! Facebookuser”
The username is not displayed.
Is this a security issue?
oztimuk on May 1st, 2009
Genius… Thank god for both you and the interweb
You just saved me a heap of time!
Thanks
frank on October 2nd, 2009
Hello hasin,
i started trying to build facebook apps reading your book but though book is good…many codes and ideas shown in the book is deprecated now…esp feeds and all…
it doesnt discuss many thing about extended permission and all(matter after platform changes)..
so i hope and suggest that new edition of book will be published soon with revised codes and all…
i wrote to packt pub as well but there was no response…
any way great book..
thanks for it