How to create a fan / like gate on Facebook?

可紊 提交于 2019-12-01 12:29:38

问题


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

  • Page Tab Name: Home
  • Page Tab URL: http://apps.talkiesmagazine.eu/facebook/home
  • Secure Page Tab URL :empty
  • Page Tab Edit URL : empty

回答1:


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.




回答2:


Not sure why the signed request isn't showing for you. It's still working.

code: http://fbmhell.com/2011/06/facebook-like-gating-in-iframe-tabs/

page tab: http://www.facebook.com/snipe.net?sk=app_207328155971716

Maybe it's something in the migration settings that you have to check/uncheck? They've made some changes over the past few months.




回答3:


Let's try this:

1, Create a simple php file on the app root named index.php with the following code:

<?

echo "POST check<br /><pre>";
print_r ($_POST);
echo "</pre>";

?>

2, Go to your app tab, and check what is come up.

2a, If the "POST check" message only, check the app URL on the app settings page. May be forget to close the url with / or there is a space somewhere.

2b, If the "POST check" message followed by an array structure, something wrong with your SDK implementation.




回答4:


Your example is using the Facebook PHP SDK by the looks of it. If you want something a bit simpler and relatively straight forward to implement, then take a look at this Facebook Fan / Like Gate over on GitHub.

I've used it on a bunch of Facebook tabs in the past and it's served me well. There's also a 'JavaScript setup' branch with the js sdk and application config setup and ready to go.



来源:https://stackoverflow.com/questions/8560385/how-to-create-a-fan-like-gate-on-facebook

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