How can I make a facebook app work only on my page?
I wrote an app that works as a page tab, but I don't want others to use it. Is开发者_如何学C it possible to make the app work only on my page?
Also, If it is possible to redirect the user to my page if he accessed the app through another page?
This is somewhat crude but should work. This will check if the current page ID is your page ID and if not display an error message.
<?php
// Include the Facebook PHP SDK
require('includes/fbSDK/facebook.php');
// Enter your app details
$app_id = "xxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
// Get the curren page ID
$page_id = $signed_request["page"]["id"];
// Enter your page ID
$mypageID = '123456789';
if ($page_id == $mypageID):
include('/your/app/files.php');
elseif ($page_id != $mypageID):
echo "This app only works on a single page!";
endif;
?>
Here are some examples of what you can check for:
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];
You can for example use this method to require someone to like a page before you show content.
Hope this helps!
精彩评论