Using fb:ref to Automatically Update an App With User-specific Data

by Joe Lanman

Overview

The fb:ref tag is your friend. It allows you to place a reference on a user's profile, and send content to this reference whenever you want.

 

Process

There are two types of fb:ref tag - handle and URL. Handle allows you change content directly, URL points to a script to get an update.

Using fb:ref handle

  1. Store a handle for each user (eg. user id) in a database or file
  2. Write a handle tag to the user's profile using profile_setFBML: <fb:ref handle="UNIQUE_HANDLE_HERE" />
  3. Write a script to loop through your handles and use facebook.fbml.setRefHandle("UNIQUE_HANDLE_HERE", "FBML_Content") to update
  4. Add a Crontab to run this script periodically

Using fb:ref url

  1. Store a handle for each user (eg. user id) in a database or file
  2. Write an update script , eg. update.php, to take a user handle as a parameter and render the relevant data
  3. Write a URL tag to the user's profile using profile_setFBML: <fb:ref url="http://www.mysite.com/update.php?handle=UNIQUE_HANDLE_HERE" />
  4. Write a script to loop through your handles and use facebook.fbml.refreshRefUrl("http://www.mysite.com/update.php?handle=UNIQUE_HANDLE_HERE") to update
  5. Add a Crontab to run this script periodically

Neither of these options require you to have the specific users logged in - but you must have your own infinite session enabled.