I've created a Facebook page and I want to add a so called Like-Gate for it. The problem is that the page is with timeline and every tutorial I've found so far is for the old Facebook pages. Is there a way to create a like gate with the new pages?
First you have to create a general facebook application: https://developers.facebook.com/apps
After that, you can add the application (with fan gate logic) as Page Tab
to your site.
Here the official facebook tutorial for page tabs:
https://developers.facebook.com/docs/appsonfacebook/pagetabs/
When a user selects your Page Tab, you will receive the signed_request parameter with one additional parameter, page. This parameter contains a JSON object with an id (the page id of the current page), admin (if the user is a admin of the page), and liked (if the user has liked the page). As with a Canvas Page, you will not receive all the user information accessible to your app in the signed_request until the user authorizes your app.
You will need to create an app for your page, and use the Facebook PHP SDK. This code worked for me:
<?php
require 'facebook.php';
$app_id = "APPID";
$app_secret = "APPSECRET";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
?>
Then include <?php if ($like_status) { ?>
before your HIDDEN content.
<?php } else { ?> In between your HIDDEN content and content for non-likers.
And lastly close off the content with to close the IF statement:
<?php } ?>
来源:https://stackoverflow.com/questions/9886132/create-like-gate-for-page