So i've checked the internet to execute a code after a user liked a facebook page.
<html>
<head>
<title>Your Website Title</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '1517163758543318',
autoLogAppEvents : true,
xfbml : true,
version : 'v3.1'
});
FB.Event.subscribe('edge.create', function(href, widget) {
alert('You just liked the page!');
console.log('You just liked the page!11111111111111');
});
};
(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 = 'https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v3.1&appId=380576395482732&autoLogAppEvents=1';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div
class="fb-like"
data-href="https://www.facebook.com/When-you-dont-know-what-to-do-281837755939599/"
data-layout="standard"
data-action="like"
data-size="small"
data-show-faces="true"
data-share="false">
</div>
</body>
</html>
Sometimes it alerts and sometimes it doesn't and i wonder what im doing wrong. Can someone point me to the right direction? Or give me some suggestion on doing this.
some links i've checked Facebook "Like" button callback, Facebook "Like" button callback help , Facebook FB.Event.subscribe "bug" with the edge.create callback , Can't get 'edge.create' callback to work with facebook javascript SDK , Facebook like callback function not working in opera , Facebook "Like" button callback help ,