tips for successful XFBML rendering
if you are creating a FBConnect application and suffering from unexpected result of XFBML renedeing in your application, here is a cool tip for you. always close yoour tag in <tag></tag> style and not like <tag/>. check out the following example for the differnece –
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head></head>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<body>
<div id="users"></div>
<fb:login-button></fb:login-button>
<script type="text/javascript">
function renderXfbml(uid) {
document.getElementById("users").innerHTML = "<fb:name uid='loggedinuser' useyou='false' /> has sent a gift to <fb:name uid='1009983642' />";
FB.XFBML.Host.parseDomTree();
}
FB.init("5b8d7fcc4d851e29908620757be663d1", "http://sandbox.ofhas.in/fbtest/xd_receiver.htm", {"ifUserConnected" : renderXfbml});
</script>
</body>
</html>
the output looks like the following one, which is no way an expected one – but the XFBML used in the example above is totally valid. it must show something like Hasin Hayder has sent a gift to Rajeeb Khan
Now check out the revised XFBML block in the following example.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head></head>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<body>
<div id="users"></div>
<fb:login-button></fb:login-button>
<script type="text/javascript">
function renderXfbml(uid) {
document.getElementById("users").innerHTML = "<fb:name uid='loggedinuser' useyou='false'></fb:name> has sent a gift to <fb:name uid='1009983642'></fb:name>";
FB.XFBML.Host.parseDomTree();
}
FB.init("5b8d7fcc4d851e29908620757be663d1", "http://sandbox.ofhas.in/fbtest/xd_receiver.htm", {"ifUserConnected" : renderXfbml});
</script>
</body>
</html>
and the output produced by the code above is perfect!
hope you will take care of this issue and prevent yourself from stumbling. happy FBConnecting
3 Responses to “tips for successful XFBML rendering”
Leave a Reply





























Abhishek on May 10th, 2009
I tried the exact same code as u have mentioned to get the name of the logged in user. i.e. I am trying to get the name “Hasin Hyder” but am not able to do so.
Can you give me some ideas to work around it?
shwetha on August 10th, 2009
i tried using the script for facebook connect. But login fails to appear on the screen…….also it says FB not defined error…Can pls throw some light on this problem. It would be of great help
kwatog on March 27th, 2010
hi! i tried your code but I have to click the button first before the names appear even though I already permitted the app.