Many Pies

Many Pies

Thursday, May 29, 2008

First steps with a facebook app

I've been working on my first facebook app. Some things I've learnt:

1. A PHP script in cgi-bin behaves differently to one not there. I should have known that really, because I have a vague concept of the cgi stuff.

2. The documentation isn't that helpful when you're starting. The footprints tutorial app is pretty good as it goes, but seems to be using an older version of the api. The anatomy overview is quite good, but it doesn't tell you how to achieve what you want in each of those areas. One thing that's confusing is how the same code, called by Facebook under different circumstances, needs to do different things. There's some good information on the page Your callback page and you.

This helps to explain the uncommented code in the footprint application:
if (isset($_POST['to'])) {
$prints_id = (int)$_POST['to'];
$prints = do_step($user, $prints_id);
} else {
if (isset($_GET['to'])) {
$prints_id = (int)$_GET['to'];
} else {
$prints_id = $user;
}
$prints = get_prints($prints_id);
}

though I haven't quite worked out what it does, because I don't need to for my app.

3. Javascript behaves differently. I took some code involving the Date object and put it into facebook and it behaved differently. I had to fiddle around before I found out what would work and what didn't. For example.
new Date("December 31, 2025 00:00:00")
returned some other date.
I had to use
end_date = new Date(2025,11,31);
end_date.setHours(0,0,0);

The months start at 0. The hours, minutes, seconds are ignored on the constructor. All very strange.

4. It says this in the documentation, but its worth repeating - the stuff your app does in a profile is static and won't update when the profile page is loaded, so you have to find another way of doing it, e.g. on a click, or when the user interacts with the app.

5. If you're tweaking your app and you want to change the way it looks on everyone's profiles look at Fb:ref.
Good fun working on this though.

2 comments:

Anonymous said...

so what will you app do? That must be fun!

Paul Morriss said...

You'll have to wait and see...
It's called Vision 2025, which may give a clue.