繁体   English   中英

Facebook登陆页面在被喜欢后发生变化

[英]Facebook landing page to change after being liked

试图向喜欢我的页面的用户显示其他页面,正在使用此代码,但似乎不起作用,有人可以帮忙吗?

基本上,它应该显示主要的index.html作为登录页面,然后当人们单击“赞”按钮时,它将显示fans_only.html页面,在用户喜欢该页面后欢迎他们。

<?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>

试试这个代码:

$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

}

我正在尝试使用类似的代码来建立一个欢迎页面(fan / nofan)页面,但是作为一个noobie,我缺少有关程序(index.php文件)如何知道要显示哪个页面以及该页面在哪里的步骤是。 是将HTML代码插入到index.php文件中,还是有对对象的调用。 这是为两个不同的欢迎页面设置的facebook sdk。

<?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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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