简体   繁体   English

检查用户是否喜欢Facebook页面

[英]Check if User liked Facebook page or not

I have the following Code, its a button to like a facebook page, and alerts: Thanks for the Like, I was trying to check on page load to see if the user has already liked the page or not, and alert "Page already liked" or "Page is not liked yet". 我有以下代码,其按钮喜欢一个Facebook页面,并发出警报:感谢Like,我正尝试检查页面加载情况,以查看用户是否已经喜欢该页面,并发出“页面已喜欢”警报”或“尚不喜欢该页面”。

<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>

I tried this but it didn't work : 我尝试了这个,但是没有用:

<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>

Any help guys? 有帮助吗?
thanks 谢谢

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

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 创建一个新的应用程序作为页面选项卡,并在index.php上使用此代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM