Facebook 签名请求问题

发布于 2024-11-02 05:27:59 字数 1014 浏览 1 评论 0原文

我想为我的 facebook 页面编写一个 fangate,但它不起作用,而且我在互联网上找不到任何帮助

require 'facebook.php';

$app_id = '16850872653xxxx';
$app_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));

$signed_request = $_REQUEST['signed_request'];

//echo $signed_request;

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

// check sig
$expected_sig = hash_hmac('sha256', $payload, $app_secret, $raw = true);

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

if($signed_request->page->liked) {
echo "This content is for Fans only!";
} else {
echo "Please click on the Like button to view this tab!";
}

我正在使用此代码...但它只是跳转到 github,我在那里下载了 facebook.php... ?

有人发现这段代码有问题吗

require 只是跳转到 github 并且 json_decode 不起作用......

I want to write a fangate for my facebook page, but it didnt work and i doesnt find any help on the inter net

require 'facebook.php';

$app_id = '16850872653xxxx';
$app_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));

$signed_request = $_REQUEST['signed_request'];

//echo $signed_request;

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

// check sig
$expected_sig = hash_hmac('sha256', $payload, $app_secret, $raw = true);

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

if($signed_request->page->liked) {
echo "This content is for Fans only!";
} else {
echo "Please click on the Like button to view this tab!";
}

I am using this code... but it just jumps to github where i have downloaded the facebook.php....

does anybody see a problem with this code?

the require just jumps to github and the json_decode doesnt work...

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

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

发布评论

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

评论(1

不知所踪 2024-11-09 05:27:59

您发送的代码有一些错误。这就是我使用的方法,并且它有效:

if (isset($_REQUEST['signed_request'])) {
      $encoded_sig = null;
      $payload = null;
      list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
      $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
      $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
      if($data->page->liked) {
          echo "This content is for Fans only!";
        } else {
          echo "Please click on the Like button to view this tab!";
        }
    }

并且不要在论坛上发布您的应用程序密钥,请尽快编辑您的帖子。

There are a few errors with the code you sent. This is what I use, and it works:

if (isset($_REQUEST['signed_request'])) {
      $encoded_sig = null;
      $payload = null;
      list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
      $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
      $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
      if($data->page->liked) {
          echo "This content is for Fans only!";
        } else {
          echo "Please click on the Like button to view this tab!";
        }
    }

And don't post your application secret key on the forum, please edit your post as soon as possible.

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