Facebook签署了请求问题

时间:2011-04-18 13:25:15

标签: facebook github json

我想为我的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不起作用......

1 个答案:

答案 0 :(得分:5)

您发送的代码存在一些错误。这是我使用的,它的工作原理:

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!";
        }
    }

请勿在论坛上发布您的申请密钥,请尽快编辑您的帖子。