Facebook Fan Gate - 展示“揭秘”内容

发布于 2024-12-08 10:08:40 字数 1058 浏览 0 评论 0原文

我正在尝试向我的页面添加粉丝门,并且我可以显示“喜欢前”的内容,但在我喜欢该页面后 - 喜欢后的内容不会显示。无论我是否喜欢该页面,它都会显示相同的预赞内容。

这是我在 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);
 }

 ?>

我看过六个示例,它们本质上都是相同的(有一些变体,有些使用图像而不是 html,有些在同一页面中使用 html) ,但都没有显示类似帖子的内容。

我从代码中删除了应用程序 ID 和密钥,尽管我确实拥有它们并且一直在使用它们。

任何帮助都会很棒。

I'm trying to add a fan gate to my page, and I can get the "pre-like" content to show, but after I like the page - the post-like content isn't showing up. It shows the same pre-like content, regardless of whether I like the page or not.

This is the code I'm using in my index.php file...

 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);
 }

 ?>

I've looked at half-dozen examples, and they're all essentially the same (with a few variants, some use images over html, some use the html in the same page), but none of them show the post-like content.

I removed the app id and secret from the code, though I do have them and have been using them.

Any help'd be awesome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北风几吹夏 2024-12-15 10:08:40
<?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

  }
?>
<?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);
 }

 ?>

Try this :)

EDIT:

Or try this version without the FB PHP-SDK, this is the solution I use for fangating so i don't need the user the whole 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

  }
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文