facebook iFrame application
Facebook has been hyper active these first weeks of 2011 and keeping us developers and community managers on our toes. The latest twist for page owners was introduced on the 10th of February with the iFrame tabs for pages blog post.
I was a bit surprised to see them let go of their full control and proprietary FBML and JavaScript apps. Now you can build a facebook tab using bog standard HTML, JS and CSS. No magic, just a page within a page. They even give you a couple of hooks to detect if the user is a fan of your page and a few extra variables.
A couple of weeks ago, a nice little project landed in my lap which I managed to turn into an exercise in facebook development. The plan was to create a short quiz to promote a trade show. My suggestion for everything now is to turn it into a facebook thing and the people involved let me run with it. This resulted in over 1200 likes in a week without tossing shiny gifts and prizes to the fans.
It was a pretty straight forward implementation aside from trying to post the results to a facebook stream. The documentation from facebook is getting quite confusing as they keep changing their approach for this sort of implementation. Facebook connect, social graph, FBML, javascript vs PHP it was all a bit too much.
So this post is just a way to share what I learnt from this exercise and provide a bare bones working example of a PHP facebook iframe app with stream publish functionality.
I assume you have basic PHP, HTML and JS knowledge and some experience of the facebook developer app.
Step one
Set up a new ap on http://www.facebook.com/developers/
Step two
You need to have a server to host your PHP code.
Download the facebook.php API and put it in a folder with the following code (save it as index.php). Take care to insert your own Application ID and Secret.
[cc lang="php"]
require 'facebook.php';
$app_id = "XXXYOURAPPIDXXXX"; // your application ID
$app_secret = "XXXYOURAPPSECRETXXXX"; // your application secret
$facebook = new Facebook(array(
'appId' => $app_id,
‘secret’ => $app_secret,
‘cookie’ => true
));
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
if ($like_status) { ?>
You like me!
Tell all your friends about it
} else { ?>
You don’t like me!
Fix it by giving me the thumbs up
}?>
[/cc]
Step 3
Step 4
Visit the Application page and put it on one of your own pages. You need to add it as a page in the Apps section of your own page settings as well.
This is just provided as is and you can see a demo of it on my FB dev page.

