Facebook – How to create a fan / like gate on Facebook

facebookfacebook-appsfacebook-like

I am trying to create a simple fan/like gate. Where you specify one content for none fans and other content for fans (if they pressed the like button). However when I run the page in the page tab it does not return a signed request and thus there is no way for me to figure out how to do it. Can someone post a tutorial, or have a fix for this? At this point I got the following code:

index.php

<?php
require dirname( __FILE__ ) . '/../api/facebook.php';

// Create our application instance
// (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => '112458478872227',
  'secret' => 'X',
  'cookie' => true
));

$signed_request = $facebook->getSignedRequest();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <title>Home</title>
</head>
<body>

<?php 
if ( $signed_request['page']['liked'] ) 
{
    echo 'A fan';
}
else
{
    echo 'Not a fan yet.';
}
?>

</body>
</html>

Link:

http://www.facebook.com/talkieslifestylemagazine?sk=app_112458478872227

Faceook App:

Page Tab

Best Answer

It looks like the original poster switched to using Wildfire's like gate app. But anyway...

Your server is doing a redirect before your script is run. If you put your code in a folder such as http://apps.talkiesmagazine.eu/facebook/home/index.php - but you specify http://apps.talkiesmagazine.eu/facebook/home as your url - the webserver will see that http://apps.talkiesmagazine.eu/facebook/home is a folder and redirect to http://apps.talkiesmagazine.eu/facebook/home/. That redirect doesn't preserve the POST data which carries the signed request. You can see if you put http://apps.talkiesmagazine.eu/facebook/home in your browser, it is redirected to http://apps.talkiesmagazine.eu/facebook/home/.

Changing your tab url to http://apps.talkiesmagazine.eu/facebook/home/ will fix it.

However, Facebook requires that you have your server setup for securely serving your app over https and set the secure tab url to that url. You have the Secure Page Tab URL empty, so that would need to be changed as well to have a fully functional tab.

Related Topic