1

我正在创建一个 facebook 标签页,我想使用扇形门控。

我以前使用过扇形门控并且没有任何问题,但这就像 4 个月前一样。而且我使用的是相同的 PHP,但这次我遇到了问题。

请参阅下面我的应用程序的基本代码和扇形门条件语句......

但由于某种原因,我得到了这个错误......

注意:未定义的索引:第 126 行 /home/sites/example.co.uk/www/competition/index.php 中的 signed_request 注意:未定义的偏移量:/home/sites/example.co.uk/www/competition/ 中的 1第 128 行的 index.php 喜欢


诡异的..

我以前从来没有使用过这个问题,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>
4

2 回答 2

0

我设法让扇门以这种方式工作。

似乎更简单,工作也很好。

我也将页面管理员视为“喜欢”的粉丝......

<?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>
于 2012-06-25T14:20:22.663 回答
0

signed_request可能丢失的唯一原因是重定向。确保您的应用没有重新加载 iframe 或将 iframe 重定向到您网站上的另一个页面。signed_request仅在初始页面上可用,除非您在页面之间手动传递它。

于 2012-06-25T11:25:51.257 回答