September 8, 2012 2

Force users to LIKE your fanpage – Facebook Flash AS3 & PHP, Part4

By in Facebook API, Freebies, PHP

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.

Page Tab Facebook Settings

Page Tab Facebook Settings

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:

Add Facebook Page Tab

Add Facebook Page Tab

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!

Source files >> FB / PHP Part4 – Force user to like your fanpage (695)

2 Responses to “Force users to LIKE your fanpage – Facebook Flash AS3 & PHP, Part4”

  1. chuchNo Gravatar says:

    Thank you very much for script share here.
    I have a problem is : my app not visible to visitor
    visit here https://www.facebook.com/gotoads/app_410560122352042
    when I am adminitrator I can see same as your example.

  2. gitarrenunterricht in muenster,facebook motetNo Gravatar says:

    Woah this blog is excellent i like reading your articles. Stay up the good work! You know, lots of people are searching round for this info, you could aid them greatly.

Leave a Reply