Facebook粉丝门 - 显示'显示'内容

时间:2011-10-05 23:36:06

标签: php facebook-like

我正在尝试为我的页面添加一个扇形门,我可以获得要显示的“预先”内容,但在我喜欢该页面之后 - 类似帖子的内容没有显示出来。无论我是否喜欢该页面,它都显示相同的预先内容。

这是我在index.php文件中使用的代码......

 require 'facebook.php';
 $app_id = "myappid";
 $app_secret = "myappsecret";
 $facebook = new Facebook(array(
 'appId' => $app_id,
 'secret' => $app_secret,
 'cookie' => true
 ));

 $signed_request = $facebook->getSignedRequest();

 $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"];

 // If a fan is on your page
 if ($like_status) {
 $a = file_get_contents("dolike.html");
 echo ($a);
 } else {
 // If a non-fan is on your page
 $a = file_get_contents("dontlike.html");
 echo ($a);
 }

 ?>
require 'facebook.php'; $app_id = "myappid"; $app_secret = "myappsecret"; $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true )); $signed_request = $facebook->getSignedRequest(); $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"]; // If a fan is on your page if ($like_status) { $a = file_get_contents("dolike.html"); echo ($a); } else { // If a non-fan is on your page $a = file_get_contents("dontlike.html"); echo ($a); } ?>

我看了六个例子,它们基本上都是一样的(有一些变种,有些使用html上的图像,有些使用同一页面中的html),但没有一个显示帖子类似内容。

我从代码中删除了app id和secret,虽然我确实已经拥有它们并且一直在使用它们。

任何帮助都很棒。

1 个答案:

答案 0 :(得分:3)

<?php
 require 'facebook.php';
 $app_id = "myappid";
 $app_secret = "myappsecret";
 $facebook = new Facebook(array(
 'appId' => $app_id,
 'secret' => $app_secret,
 'cookie' => true
 ));

 $signed_request = $facebook->getSignedRequest();

 $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"];

 // If a fan is on your page
 if ($like_status == 1) {
 $a = file_get_contents("dolike.html");
 echo ($a);
 } else {
 // If a non-fan is on your page
 $a = file_get_contents("dontlike.html");
 echo ($a);
 }

 ?>

试试这个:)

编辑:

或者尝试没有FB PHP-SDK的这个版本,这是我用于fangating的解决方案所以我不需要用户整个PHP-SDK

<?php
  $app_secret="xxxxxxxxxxxxx";
  $data = parse_signed_request($_REQUEST['signed_request'], $app_secret);
  $page_data=$data['page'];

  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, '-_', '+/'));
  }

  if($page_data['liked'] == "1"){

    // Fan Content

  }else{

    // No-Fan Content

  }
?>