我正在创建一个Facebook标签页,我想使用粉丝选通。
我之前使用过风扇门控并且没有任何问题,但这就像4个月前一样。我正在使用相同的PHP,但这次我遇到了问题。
请参阅下面我的应用程序的基本代码和扇形门条件声明...
但是由于某种原因我得到了这个错误......
注意:未定义索引:第126行/home/sites/example.co.uk/www/competition/index.php中的signed_request 注意:未定义的偏移量:第128行/home/sites/example.co.uk/www/competition/index.php中的1 像
怪异..
我之前从未遇到过使用过这个问题,facebook改变了它的运作方式吗?
任何帮助都会非常感谢。
<?php
$fb_app_id = '000000000000000';
$fb_secret = '00000000000000000000000000000000';
$fb_app_url = 'http://example.co.uk/competition';
$fb_tab_url = 'http://www.facebook.com/example/app_000000000000000';
$fb_channel = '//example.co.uk'
require 'src/facebook.php';
//Create facebook application instance.
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true,
));
?>
<!DOCTYPE html>
<html>
<head>
<meta property="fb:app_id" content="<?php echo $fb_app_id ?>" />
</head>
<body>
<div id="fan-gate">
<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["page"]["liked"])) {
?>
LIKE US...
<?php } else { ?>
<strong>YOU'VE LIKED OUR PAGE, THANKS!!!</strong>
<?php } ?>
</div>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $fb_app_id ?>',
channelUrl : '<?php echo $fb_channel ?>/channel.html', // Channel File
cookie: true,
xfbml: true,
oauth: true,
status: true
});
FB.Canvas.setAutoGrow(true);
};
</script>
</body>
</html>
也尝试了这个,但它总是只说第二个条件,即使我不喜欢这个页面。
<?php
$fb_app_id = '000000000000000';
$fb_secret = '00000000000000000000000000000000';
$fb_app_url = 'http://example.co.uk/competition';
$fb_tab_url = 'http://www.facebook.com/example/app_000000000000000';
$fb_channel = '//example.co.uk'
require 'src/facebook.php';
//Create facebook application instance.
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true,
));
?>
<!DOCTYPE html>
<html>
<head>
<meta property="fb:app_id" content="<?php echo $fb_app_id ?>" />
</head>
<body>
<div id="fan-gate">
<?php
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
if($like_status){
echo 'LIKE US...';
} else {
echo '<strong>YOU'VE LIKED OUR PAGE, THANKS!!!</strong>';
}
?>
</div>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $fb_app_id ?>',
channelUrl : '<?php echo $fb_channel ?>/channel.html', // Channel File
cookie: true,
xfbml: true,
oauth: true,
status: true
});
FB.Canvas.setAutoGrow(true);
};
</script>
</body>
</html>
答案 0 :(得分:0)
signed_request
可能丢失的唯一原因是因为重定向。确保您的应用没有重新加载或将iframe重定向到您网站上的其他网页。 signed_request
仅在初始页面上可用,除非您在页面之间手动传递它。
答案 1 :(得分:0)
我设法让扇子以这种方式工作。
看起来很简单,效果也很好。
此外,我还要对页面管理员进行处理,例如&#39;喜欢&#39;风扇...
<?php
$fb_app_id = '000000000000000';
$fb_secret = '00000000000000000000000000000000';
$fb_app_url = 'http://example.co.uk/competition';
$fb_tab_url = 'http://www.facebook.com/example/app_000000000000000';
$fb_channel = '//example.co.uk'
require 'src/facebook.php';
//Create facebook application instance.
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true,
));
$signedRequest = $facebook->getSignedRequest();
?>
<!DOCTYPE html>
<html>
<head>
<meta property="fb:app_id" content="<?php echo $fb_app_id ?>" />
</head>
<body>
<div id="fan-gate">
<?php if ( ( $signedRequest['page']['liked'] || $signedRequest['page']['admin'] ) == 1 ) { ?>
Like us...
<?php } else { ?>
<strong>You've Liked our page</strong>
<?php } ?>
</div>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $fb_app_id ?>',
channelUrl : '<?php echo $fb_channel ?>/channel.html', // Channel File
cookie: true,
xfbml: true,
oauth: true,
status: true
});
FB.Canvas.setAutoGrow(true);
};
</script>
</body>
</html>