I'm creating a facebook tab page and I would like to use fan gating.
I've used fan gating before and have had no problems, but this was like 4 months ago. And I'm using the same PHP but this time I'm getting problems.
See below the basic code for my app and the fan gate conditional statement...
But I get this error for some reason...
Notice: Undefined index: signed_request in /home/sites/example.co.uk/www/competition/index.php on line 126 Notice: Undefined offset: 1 in /home/sites/example.co.uk/www/competition/index.php on line 128 Like
Weird..
I've never had problems with using this before, has facebook changed the way this works?
Any help would be much a appreciated thanks.
<?php
$fb_app_id = '000000000000000';
$fb_secret = '00000000000000000000000000000000';
$fb_app_url = 'http://example.co.uk/competition';
$fb_tab_url = 'http://www.facebook.com/example/app_000000000000000';
$fb_channel = '//example.co.uk'
require 'src/facebook.php';
//Create facebook application instance.
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true,
));
?>
<!DOCTYPE html>
<html>
<head>
<meta property="fb:app_id" content="<?php echo $fb_app_id ?>" />
</head>
<body>
<div id="fan-gate">
<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["page"]["liked"])) {
?>
LIKE US...
<?php } else { ?>
<strong>YOU'VE LIKED OUR PAGE, THANKS!!!</strong>
<?php } ?>
</div>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $fb_app_id ?>',
channelUrl : '<?php echo $fb_channel ?>/channel.html', // Channel File
cookie: true,
xfbml: true,
oauth: true,
status: true
});
FB.Canvas.setAutoGrow(true);
};
</script>
</body>
</html>
Also tried this, but it always just says the second condition, even tho I haven't like the page.
<?php
$fb_app_id = '000000000000000';
$fb_secret = '00000000000000000000000000000000';
$fb_app_url = 'http://example.co.uk/competition';
$fb_tab_url = 'http://www.facebook.com/example/app_000000000000000';
$fb_channel = '//example.co.uk'
require 'src/facebook.php';
//Create facebook application instance.
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true,
));
?>
<!DOCTYPE html>
<html>
<head>
<meta property="fb:app_id" content="<?php echo $fb_app_id ?>" />
</head>
<body>
<div id="fan-gate">
<?php
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
if($like_status){
echo 'LIKE US...';
} else {
echo '<strong>YOU'VE LIKED OUR PAGE, THANKS!!!</strong>';
}
?>
</div>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $fb_app_id ?>',
channelUrl : '<?php echo $fb_channel ?>/channel.html', // Channel File
cookie: true,
xfbml: true,
oauth: true,
status: true
});
FB.Canvas.setAutoGrow(true);
};
</script>
</body>
</html>