Facebook粉丝门页不会捡到除了我自己以外的任何人的喜欢?

时间:2011-12-08 12:16:14

标签: php facebook-graph-api facebook-php-sdk

我正在尝试为Facebook页面创建一个自定义选项卡,它在页面选项卡中的firefox,chrome和Internet Explorer 8中完全适用于我,并且作为直接链接,但对于其他人来说,它只是没有'拿起他们的喜欢。

这是我的代码:

require 'src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
    'appId' => 'xxxxxxxx',
    'secret' => 'xxxxxx',
));

$user = $facebook->getUser();


// alternative to the below but only works on the facebook tab itself
$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"])) {
echo "You are not a fan!";
} else {
echo "Welcome back fan!";
}

if ($user) {
try {
    $likes = $facebook->api("/me/likes/xxxxxxxxxx");
    if( !empty($likes['data']) )
    {
        ?>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script type="text/javascript">
        $(document).ready(function() {
            $('#fan').click(function() {
                $('#fan').animate({
                    opacity: 0.2,
                    width: 'auto',
                    height: 'auto'
                }, 1000, function() {
                    // Animation complete.
                    $('#fan').hide('slow');
                    $('#voucher').show('slow');
                });
            });
        });
        </script>

        <a href="#"><img id="fan" src="//www.website.com/facebook/2011/voucher/fans_image.jpg" alt="10% off" style="border:0;" /></a>
        <div style="display:none; position:absolute; top:0; left:0;" id="voucher" >
        <a href="//www.website.com/facebook/2011/voucher/EYE-TEST-DECEMBER-11.pdf" target="_blank"><img src="//www.website.com/facebook/2011/voucher/fb-voucher-dec11.jpg" style="border:0;" alt="10% off" /></a>  <br />
        <p style="text-align:center"><a href="//www.website.com/facebook/2011/voucher/EYE-TEST-DECEMBER-11.pdf" target="_blank">Click here to download PDF version of the voucher.</a></p>
        </div>
        <?php
    }
    else
    {
        ?>
        <img style="position:absolute; top:0; left:0; border:0;" id="all" src="//www.website.com/facebook/2011/voucher/fb_like_page.jpg" width="520" height="304" alt="Click LIKE button to get 10% off." />
        <?php
    }
} catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
    }
}

if ($user) {
    $logoutUrl = $facebook->getLogoutUrl();
} 
else {
    //user isn't logged in so just show un-liked image
    ?>
    <img style="position:absolute; top:0; left:0; border:0;" id="all" src="//www.website.com/facebook/2011/voucher/fb_like_page.jpg" width="520" height="304" alt="Click LIKE button to get 10% off." />
    <?php
    $loginUrl = $facebook->getLoginUrl(array(
        'scope' => 'user_likes'
    ));
}

更多信息 该应用程序在沙箱模式下

我在想,因为该应用程序出现在我的帐户设置中,这就是为什么它只适用于我,但如果我查看其他粉丝选项标签,他们就不会弹出权限通知,以便可以&是不是这样?

1 个答案:

答案 0 :(得分:1)

持久性通知适用于明确授权应用的用户,这是您似乎已完成的操作。您向拥有和未授权申请的人显示信息,而不是向喜欢或不喜欢您网页的人显示

 // alternative to the below but only works on the facebook tab itself
 $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"])) {
  echo "You are not a fan!";
  } else {
  echo "Welcome back fan!";
  }

这里的代码是我希望喜欢或不喜欢页面选项卡的人。这与授权位于该选项卡上的应用程序无关。当用户喜欢您的页面时,您无法访问其用户ID等,只有他们喜欢该页面。但是您的代码似乎正在使用api来测试用户是否喜欢该页面。我的猜测是你的用户对象实际上是null,因为用户没有明确授权该页面选项卡上的应用程序。这有意义吗?

因此,除非他们已授予对该应用的访问权限:

if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} 
else {
//user isn't logged in so just show un-liked image
?>
<img style="position:absolute; top:0; left:0; border:0;" id="all" src="//www.website.com/facebook/2011/voucher/fb_like_page.jpg" width="520" height="304" alt="Click LIKE button to get 10% off." />
<?php
$loginUrl = $facebook->getLoginUrl(array(
    'scope' => 'user_likes'
));
}

$ user将在此处为空,您将告诉人们喜欢您的网页是否已经这样做