Getting and Setting Profile FBML
Problem
I want to get and set the contents of my users’ Profile Boxes and Profile Action links.
Solution
Use the Profle.getFBML()
and Profile.setFBML()
methods to manipulate the contents of your app’s Profile
Box.
Discussion
The process of setting FBML is similar to the process that takes place behind the scenes when a user requests a page from your app (see Under the Hood: How Facebook Apps Work). In this case, the process is less symmetrical, since you initiate an update to Facebook’s cache that they’ll later display. The FBML update flow is illustrated in Figure 9-17.
Figure 9-17. FBML update flow
The FBML you set is cached on Facebook’s servers to make
displaying Profiles as quick as possible, so you’ll need to use
Profile.setFBML()
again if you
want to update the cache:
Whenever your app feels the need to update Profile FBML, you call
Profile.setFBML()
from your app server and send your new content to Facebook’s servers, where it gets cached. This generally happens either because you have a user currently logged in who has done something Profile-worthy, or because you have a scheduled job (possibly usingcron
) that has resulted in a calculation.A visitor to one of your users’ Profiles requests the page from Facebook.
Facebook renders your cached FBML into HTML (along with all of the other cached Profile Boxes and Action links for this user) and serves ...
Get Facebook Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.