简体   繁体   中英

Facebook landing page to change after being liked

am trying to show users who liked my page a different page, am using this code but it doesnt seem to be working, can anyone help?

basically it should show the main index.html as the landing page then when people click the like button it will show the fans_only.html page to welcome the users after they like the page.

<?php
require_once 'facebook/facebook.php';
/*
 * "appId" and "secret" values get from your Facebook application settings
 */
$config = array (
    'appId' => 'xxx',
    'secret' => 'xxx'
);
$facebook = new Facebook ($config);
{

    $signed_request = $facebook->getSignedRequest();

    if ($signed_request)
    {
        if (isset ($signed_request ['page'] ['liked']) && $signed_request ['page'] ['liked'])
        {
            //Place your secret content here
            //echo '<p>This is a secret content.</p>';
            require ("fans_only.html");
            exit;
        }
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>intro</title>
<!--Adobe Edge Runtime-->
    <script type="text/javascript" src="edge_includes/jquery-1.6.2.min.js"></script>
    <script type="text/javascript" src="edge_includes/jquery.easing.1.3.js"></script>
    <script type="text/javascript" src="edge_includes/edge.0.1.3.min.js"></script>
    <script type="text/javascript" src="edge_includes/edge.symbol.0.1.3.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="index_edge.js"></script>
    <script type="text/javascript" charset="utf-8" src="index_edgeActions.js"></script>
    <link rel="stylesheet" href="index_edge.css" />
<!--Adobe Edge Runtime End-->
<style type="text/css">

        body {
            background:url(images/preloader.gif) 255px 10px no-repeat #fff;
        }
</style>        

</head>

<body style="margin:0;padding:0;">
    <div id="stage" class="EDGE-22385971">
    </div>
</body>

</html>

Try this code:

$facebook = new Facebook(array(
  'appId'  => 'APP_ID',
  'secret' => 'APP_SECRET',
  'cookie' => true,
));

$session = $facebook->getSession();

$me = null;

if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
  }
}


$signed_request = $_REQUEST["signed_request"];

function parse_signed_request($signed_request, $secret) {
  list($encoded_sig, $payload) = explode('.', $signed_request, 2);

  // decode the data
  $sig = base64_url_decode($encoded_sig);
  $data = json_decode(base64_url_decode($payload), true);

  if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
    error_log('Unknown algorithm. Expected HMAC-SHA256');
    return null;
  }

  // check sig
  $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
  if ($sig !== $expected_sig) {
    error_log('Bad Signed JSON signature!');
    return null;
  }

  return $data;
}

function base64_url_decode($input) {
  return base64_decode(strtr($input, '-_', '+/'));
}

$data = parse_signed_request($_REQUEST["signed_request"], "APP_SECRET");


if ($data['page']['liked']){

  //SHOW DATA FAN

}else{

   //SHOW DATA NO FAN

}

I am trying to set up a welcome page (fan/nofan) pages using similar code, but as a noobie, I am missing a step as to how the program (the index.php file) knows what page to display and where that page is. Is the HTML code inserted into the index.php file or is there a call to an object. Here is the facebook sdk set up for two different welcome pages.

<?php
require_once './facebooksdk/src/facebook.php';  //download at https://github.com/facebook/php-sdk/downloads

$facebook = new Facebook(array(
  'appId' => '174968482618267', // enter your App's ID
  'secret' => '5710d00a9b4acec8849d8adeb08c15c4', // enter your App's Secret
  'cookie' => true,
));
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Welcome Page</title>
</head>
<body>

<?php
// Did they like a page?
$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"])) {
// DISPLAY TO: those who didn't LIKE the page
    ?>


<!-- Didn't Like -->

You don't "Like" our page :-(

<!-- End of Didn't Like -->
    <?
} else {
// DISPLAY TO: those who LIKED the page
    ?>

<!-- Liked -->

Thanks for "Liking" our page!

<!-- End of Liked -->
<? } ?>

<!-- follow @svolinsky on twitter -->

</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM