Today, I want to show you how to enable the application on fanpage and how to force users / players to like fanpage before they can use it. Don’t belevie that your agency will get new clients because you have made great and fun application or game. It’s all about:
- New users
- Quantity of Likes
Updated demo here >>
This time we use exclusively PHP goodness. But first things first. To create your own fanpage go here . Now let’s implement some changes in the application settings. Enable Page Tab and fil it with the same values as App on Facebook area.
Cool , now let’s change Website with Facebook Login. For security reasons, Facebook redirects only to this url. Previously, users were guided to the address of the canvas, and now we want them to be redirected to pagetab url.
Now that we have it we can move on to adding application to your newly created fanpage. All you need to do is to run this url: https://www.facebook.com/dialog/pagetab?app_id=YOUR_APP_ID&next=YOUR_URL where:
- YOUR_APP_ID – is your app id
- YOUR_URL – is your App’s Canvas URL
You should see something like this:
Great, now let’s moveto the main parts of this post. We will implement functionality that allows us to check user whether he is a fan of our page If so, run the application, if not, we will show image with an information to click Like button.
The magic happens at the beggining of index.php file:
<?php
require_once("facebookPHP/facebook.php");
$config = array(
'appId' => 'YOUR APP ID,
'secret' => 'FILL YOUR APP SECRET'
);
$facebook = new Facebook($config);
try {
$signedRequest = $facebook->getSignedRequest();
$liked = $signedRequest['page']['liked'];
$appData = $signedRequest['app_data'];
}
catch(FacebookApiException $e) {
error_log($e->getType());
error_log($e->getMessage());
}
?>
Note that require_once(“facebookPHP/facebook.php”) is refering to new facebook.php file that you will find in source files package. Of course the most important value for us is $liked Boolean and we make use of it at the bottom like this:
<?php if( $liked ){
?>/// SHOW APPLICATION
<?php
}else{
?>// SHOW IMAGE
<?php
}
?>
Ohhh… Remember to change your redirect_uri in FB.getLoginStatus function to your new page tab url. Now go and collect Likes like a master!


