Menu

Facebook Apps – Hello World

Today, for one reason or another, I’ve spent sometime playing with Facebook Apps. The last time I played with Facebook was a good couple of years ago, and could remember it being a pain, not difficult, just a pain.

To start from common ground, there are likely to be some steps you’ll be able to skip, but for completeness:

1. Create a Facebook account. (Yep, I don’t (or didn’t) have one- FWIW I don’t intend to keep it much longer than finishing this first app).

2. You need some kind of PHP hosting environment. I signed up for a free account at http://www.zymic.com. There are probably others, maybe better ones, but I found it ok, and ultimately it was free!

3. Download the Facebook SDK, which is essentially a zip file containing the require php files. I uploaded the 3 .php files (facebook.php, facebook-mobile.php and facebookapi_php5_restlib.php to the root folder of my site) and also created the directory structure for the ‘jsonwrapper’ and sub-files and sub-dirs.

4. Go back to Facebook and add yourself as a developer. Then create an app, playing special attention to the API Key and the APP Secret which are generated at this stage. You also need to specify the URL of the site that is hosting your php file, as well as the Canvas URL address (which I set as gbtesterapp).

A summary of these settings is in the image below:

5. Now we need to create the index.php at the location specified in the application settings. (Its possibly worth noting it may be worth creating a simple ‘HelloWorld’ php script to prove the php server is behaving correctly).

The following is just some code to output the currently authenticated users Unique ID and their name.