Create Like-Gate for page [closed]

北慕城南 提交于 2019-12-03 09:02:53

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 } ?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!