1

我有以下代码,它是一个喜欢 facebook 页面的按钮和警报:感谢喜欢,我试图检查页面加载以查看用户是否已经喜欢该页面,并警告“页面已经喜欢”或“页面尚未被点赞”。

<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
    FB.init({appId: '637166706299573', status: true, cookie: true, xfbml: true});
    FB.Event.subscribe('edge.create', function(href, widget) {
        alert('Thanks for the Like');
    });
};
(function() {
    var e = document.createElement('script');
    e.type = 'text/javascript';
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
}());
</script>
<script type="text/javascript" src="facebook.js"></script>
<fb:like href="https://www.facebook.com/Tabyeed" layout="button_count" show-faces="true" width="450" action="like" colorscheme="light" font="arial"></fb:like>

我试过了,但没有用:

<script type="text/javascript">
function liked() {
    FB.api("me/likes/348028968575501", function(response) {
        if (response.data.length == 1) {
            alert("page liked already");
        } else {
            alert("page is NOT liked already");
        }
    });
}
</script>

有帮助吗?
谢谢

4

2 回答 2

0

I think you are looking for page tab application check like the page or not.

/**
 * get the signed request parameter and decode it to get the user's
 * 'liked' status for the current page
 */
if (!empty($_REQUEST['signed_request'])) {
  $signedRequest = $_REQUEST['signed_request'];
  list($sig, $payload) = explode('.', $signedRequest, 2);
  $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
}

/**
 * if the user has already 'liked' the page then render the 'liked' view
 * else, render the 'pre liked' view
 */
if (empty($data['page']['liked'])) {
  include 'views' . DIRECTORY_SEPARATOR . 'pre_liked.php';
} else {
  include 'views' . DIRECTORY_SEPARATOR . 'post_liked.php';
}

Create a new application as page tab and on index.php use this code

于 2013-05-03T05:35:39.290 回答
0

我没有看到登录按钮/流程,所以最好的猜测是FB.api("me/likes/348028968575501"由于用户未通过身份验证,这与不依赖身份验证的事件订阅不同,因此将失败。

于 2013-05-02T23:48:40.747 回答