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>
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With