Facebook Fan Gate-显示"Reveal"内容 [英] Facebook Fan Gate - Displaying the 'Reveal" Content
问题描述
我正在尝试在页面上添加一个扇形门,并且可以显示类似前"的内容,但是在我喜欢该页面之后,就不会显示类似后"的内容.无论我是否喜欢该页面,它都会显示相同的喜欢前内容.
这是我在index.php文件中使用的代码...
我看了六个示例,它们基本上是相同的(有一些变体,一些使用html上的图像,有些使用同一页面中的html),但是都没有显示该帖子内容.
我从代码中删除了应用ID和密码,尽管我确实有并且一直在使用它们.
任何帮助都会很棒.
<?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
}
?>
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.
<?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
}
?>
这篇关于Facebook Fan Gate-显示"Reveal"内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!