2

I need to check on my website if user(visitor) has already clicked "like" on Facebook fan page, is it possible? I want to remove "like" button if user clicked "like".

In Facebook app I can check it easily with this code:

<?php
$request = $_REQUEST["signed_request"];
list($encoded_sig, $load) = explode('.', $request, 2);
$fbData = json_decode(base64_decode(strtr($load, '-_', '+/')), true);
if (!empty($fbData["page"]["liked"]))
{ 
//if liked do....
} else {
//else do....
}
?>

But how to use similar code on my website?

3
  • I think, it is not possible using php Dec 31, 2013 at 8:44
  • Thank you for answer, doesn't matter If in PHP, can be other programming language.
    – user1816133
    Dec 31, 2013 at 8:56
  • if you want to check if a user likes your page already.. you have to make login to your website and get their 'user_likes' permissions. and then check if they like or doesnt.
    – Rasmus P
    Dec 31, 2013 at 10:07

1 Answer 1

0

Use event subscribe method from FB api:

FB.Event.subscribe('edge.create',
    function(href, widget) {
        alert('You liked the URL: ' + href);
    }
);

Another way for tracking is LikeButton data-ref. The ref setting causes two parameters to be added to the referrer URL when a person clicks a link from a stream story about a Like action:

https://www.facebook.com/l.php?fb_ref=top_left&fb_source=profile_oneline

When user click like, you will process _GET['fb_source'] parameter as you like at your website

To get statistics by url you can use link.getStats. It's method will return xml response with all statistics for url (including like). You cant get this statistics and manipulate as you wish

http://api.facebook.com/restserver.php?method=links.getStats&urls=https://www.facebook.com/myPage

http://api.facebook.com/restserver.php?method=links.getStats&urls=http://example.com
8
  • Thank you for answer, but as I think this alert will be shown only after user clicks like or not? I need to make that when user visit website, check If he is clicked like before, If yes - delete like button. Sorry for stupid question, but how I need to setup href correctly? $href = www.facebook.com/myPage ? I think this is incorrect. Could you help me, please? Thank you.
    – user1816133
    Dec 31, 2013 at 9:09
  • See my edited answer about data-ref Dec 31, 2013 at 9:10
  • I misunderstood part about data-ref. How It works? Can I see example. If my facebook fan page is: www.facebook.com/myPage how can I use this method?
    – user1816133
    Dec 31, 2013 at 9:14
  • Another way to get statistics - it is method links.getStat. See added example to my answer Dec 31, 2013 at 9:54
  • Thank you for answer. So If I get statistic, how can I check If user clicked Like? How can I get data from this statistics? http://api.facebook.com/restserver.php?method=links.getStats&urls=https://www.facebook.com/myPage How It should look like? For example: if (like is clicked...) { do... }
    – user1816133
    Dec 31, 2013 at 10:10