Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook FB.Event.subscribe does not work

I'd like to follow how many likes I get on my page, but something is wrong. I am using the Facebook javascript event handler but it doesnt work.

It should alerts me when I click on the like or on the dislike button but it does not do anything. Any idea where I am wrong? Thanks! And sorry for my english.

Here is my UPDATED code:

<!DOCTYPE html>
<html xmlns:fb="http://ogp.me/ns/fb#">
<head>
<title>FBlike check</title>
</head>
<body>
<div id="fb-root"></div>
<script>
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=00000000000000000";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk')); 

FB.Event.subscribe('edge.create',
    function(response) {
        alert('You liked the URL: ' + response);
    }
);
</script>
<fb:like href="https://www.facebook.com/XYZ" send="false" layout="button_count" width="200" show_faces="false"></fb:like>
</body>
</html>
like image 416
DNReNTi Avatar asked Feb 18 '23 21:02

DNReNTi


2 Answers

Well.. I tried a lot of versions than this one is worked perfectly:

<script>  
window.fbAsyncInit = function () {
            FB.init({
                appId: 'MY_APP_ID', 
                status: false,
                cookie: false, 
                xfbml: true
            });

            //Additional
            FB.Event.subscribe('edge.create',
                        function (response) {
                            alert('LIKED: ' + response);
                        }
                 );
        };

        // Asynchronously
        (function (d) {
            var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
            if (d.getElementById(id)) { return; }
            js = d.createElement('script'); js.id = id; js.async = true;
            js.src = "//connect.facebook.net/en_US/all.js";
            ref.parentNode.insertBefore(js, ref);
        } (document));

    </script>
    <fb:like href="https://www.facebook.com/MY_FB_PAGE" send="false" layout="button_count" width="200" show_faces="false"></fb:like>

I hope it can help for others.

like image 107
DNReNTi Avatar answered Feb 27 '23 11:02

DNReNTi


You're using the iframe version of the like button - the javascript events are only fired from the XFBML version - this is explained on the Like Button documentation

How do I know when a user clicks a Like button?

If you are using the XFBML version of the button, you can subscribe to the 'edge.create' event through FB.Event.subscribe.

like image 36
Igy Avatar answered Feb 27 '23 10:02

Igy