Thursday, February 14, 2008

Quick Facebook JavaScript and PHP API Notes

Took a quick look at and found a few obfuscations. To get started, you need to do these things (described a little too briefly in the link above).
  • Register for an application key at (Don't hit enter yet)
  • Cllick the "Optional Fields" drop down and
    • Provide a callback URL (that is, the full URL of your HTML page containing the Facebook JavaScript application).
    • Choose "IFrame" as the canvas page URL.
When it is working, this little app just prints out your friend's Facebook IDs (numbers) onto the screen. When you load your page (, you will be redirected to Facebook to login and then will go back to your URL.

Also took a quick tour of the PHP examples ("footprints" and some hello-world type stuff). Looks like the instructions for setting up the JS example assumed you were familiar with doing things the PHP way.

For footprints, you will need a web server (apache), PHP, and MySQL. Get, install, and start these in the usual ways. Hints: for Macs, get the nice disk image from MySQL. Also, read the PHP installation instructions before installing Apache, since PHP will require some non-default configuration options (particularly DSO support).

The web server provides the callback URL as well (""), which will need to be on a world accessible Apache (or other) server. Dump your application in htdocs/footprints and make sure paths are correct (index.php needs to point correctly to facebook.php). Note also that will be taken, so make a different name. The facebook app name does not have to match your callback app's name.

Create the MySQL database. The footprints PHP scripts don't do this for you.
  1. Edit config.php. You will need the root password for your db.
  2. From the command line, log into your db with /usr/local/mysql/bin/mysql -u root -p and provide the root password at the prompt. You will then need to create and switch to the footprints database.
  3. mysql> CREATE DATABASE footprints;
  4. mysql> USE footprints
  5. mysql>CREATE TABLE `footprints` ( `from` int(11) NOT NULL default '0', `to` int(11) NOT NULL default '0', `time` int(11) NOT NULL default '0', KEY `from` (`from`), KEY `to` (`to`) );
Step 5 is just a cut and paste of the config.php file from footprints, but note that they omitted the final ";" on the statement.

When it is working, this little application allows you to step on your friends. It gives you a little text area for typing names that will be autocompleted as you type. Note this must run inside Facebook, unlike the previous example.

When setting up your PHP app, you'll notice you can choose between FBML and IFrames. FBML will (as you might have guessed) a nice FaceBook styled application and some extra goodies. The IFrame option will produce a pretty bare bones footprint application, but obviously you have more power to customize the styles.

Hosting Your Services
Here are some instructions on using Amazon Web Services to host your application.

No comments: