I’ve built several facebook applications now, and although none of them are as successful as my friend Ben’s “Make A Baby” application, I’m very happy with how they run. Here are the tricks that I used – although you’ll find them mentioned elsewhere, and each of them is important by itself, if you’re just getting started on your first facebook application, you need to know:
- Facebook passes you the session key you want. Don’t try and use your typical, cookie or URL-based session – it won’t work. Instead (in php, for example,) start your session with:
- $facebook = new Facebook($api_key, $secret);
$session_key = md5($facebook->api_client->session_key);
session_id($session_key);
session_start();
- $facebook = new Facebook($api_key, $secret);
- If your application is anything like mine, you’re going to have the same FBML content used all over the place – on several people’s profiles, and in the main application itself. Rather than update the contents of thousands of profiles, Facebook provides a handy fb:ref cacheing architecture. USE IT.
- If you’re using fb:ref (which you SHOULD be), you probably want to be using the “push” method, using named handles. Add the php curl_multi hack for performance, and you’ll be off and running.
- To take advantage of this (updating huge swaths of your application without any user interaction), you’ll probably want to run a cron job, using an infinite session key. Get yourself one.
- The name of your application makes a huge difference when it comes to random users adding your application from the application directory. BUT, facebook doesn’t seem to mind if you change the name periodically, even after your application has been listed and you have piles of users. Go ahead and play around, and keep checking your facebook stats to see what works best.
Obviously, you’ll want to run a test version. The best way is to have a second application, in developer mode, and mapped to a special port that forwards traffic to your local development machine through an ssh tunnel. Read my previous blog post on how to set this up.- In order to not go INSANE managing your test version, make sure you’ve abstracted out the full facebook app path, and keep it in some local config file. (Yes, I realize this should be obvious to any experienced developer). While you’re at it, you might want to check for the best possible facebook url you can get – these things are the new domain names.
- Facebook templatized actions – you need to use these. Basically, it’s the only way to turn events within your application, into first-class citizens of the facebook news streams. They’re worthy of a full blog post on their own, as I found a whole series of gotchas when implementing them. For starters, remember to use the right fb:pronoun-s.
- Default FBML - it’s way more important than it seems, since you can’t be sure where the user’s workflow will take them when playing with/installing your application. You’ll probably want to prototype this extensively, and then copy it from your editor into the tiny little form facebook provides.
- It’s mentioned in all the facebook best practices, but it bears repeating – make sure you’re letting facebook users try out the functionality of your application before requiring them to install it. Not only will it lead to fewer unhappy users, but it maintains the reputation of facebook application developers as a group.
- Post-remove – You’ll probably find, as most facebook apps do, that you have a HUGE amount of churn in your user base. If you don’t remember to remove local user data from your application database when a facebook user removes your application, it will quickly become cluttered with cruft. (A quick FQL query for whether or not each user has your application installed can be run as a one-time cleanup if necessary.)
I hope you find these helpful – and if you’ve got further tips of your own, let me know!
UPDATE (Sept. 6th): My friend Nick wrote a book that makes this whole process easier:

#1 by Prasad at March 9th, 2008
Thanks for the tips! are really helpful.
#2 by Chester Grant at March 16th, 2008
Ok..
Let me add some stuff that I think might be critical.
1. If you have a shared host. Do your entire app in ajax so you can slowly load your app. Facebook time out is 8secs and some Hosting services can’t return in that time. This will minimize if not eliminate the screen of death, called Response Time.
2.And if you are running dedicated hosting try doing preload fql. The fql statements take up tons of time to do.
#3 by varun at April 17th, 2008
question : I have a website – movies rating system – it has its own datase of movies and members. I wish to create facebook application for this.
Do i need to keep 2 separate databases – one for my website data and one for facebook data ?
#4 by admin at April 17th, 2008
Varun:
No, you can keep all the data in a single database. But you’re going to need at least a couple of extra fields for each user, and it’s probably simpler to define a new table and join them – this is to keep the session keys for each user, so that you can update their profile data while they’re not on your application page.
#5 by Dave K at August 11th, 2008
What do you mean by “abstracted out the full facebook app path”?
#6 by admin at August 11th, 2008
@Dave K – You’re going to end up with a facebook app path that looks like this:
http://apps.new.facebook.com/birthday/
And a test app that looks like this:
http://apps.new.facebook.com/test-birthday/
And you’re going to have callback urls of
http://myserver.somedomain.com/facebook-apps/birthday/
http://myserver.somedomain.com:8080/fb-birthday-test/
Or whatever.
You’ll find (especially when you start dealing with uploading images, etc.) that you need these full urls in a few places in your templates. Places you don’t think they OUGHT be to needed. Make sure you’re using template variables for that, so that you can manage your test server and your real server with the same codebase, and so that you don’t have to remember to flip a switch somewhere before you commit your code every time. The config file should be svn-ignore (or equivalent in git, or whatever your favorite revision-control-system is today).
If you’re making pretty RESTian interfaces to your apps, you’re still going to have a bunch of /object/controller/action/param-type stuff that goes on the end of these paths. Which is, obviously, fine.
Joshua
#7 by Rich Wilson at June 5th, 2009
I am new to this and when I set the app up I only was able to send it to 3 people… How do I change that?
As I said.. Im new to this and confused.
Thanks so very much!!!