Facebook 签名请求问题
我想为我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发送的代码有一些错误。这就是我使用的方法,并且它有效:
并且不要在论坛上发布您的应用程序密钥,请尽快编辑您的帖子。
There are a few errors with the code you sent. This is what I use, and it works:
And don't post your application secret key on the forum, please edit your post as soon as possible.