3

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 ,

jameshwart lopez
  • 2,993
  • 6
  • 35
  • 65

1 Answers1

4

If you check https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v3.1, you’ll notice that the edge.create event type is not listed there any more.

Facebook has removed this - they do not want sites to be able to "force" a like, by presenting the user with a like button and then waiting for this event, any more.

The only events you can subscribe to now via the JS SDK are related to the auth status changing, and when social plugins embedded into a page have been rendered.

https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/?locale=en_US:

edge.create and edge.remove JS SDK Events: These Events will no longer be accessible. As an alternative, you can use our Webhooks and be notified every time someone likes one of your Facebook Pages.

misorude
  • 3,381
  • 2
  • 9
  • 16