Search code examples
javascriptfacebookfacebook-javascript-sdkfacebook-likefacebook-sdk-4.0

Facebook share and like with callback doesn't run the callback and popup not opening every time


I was trying to implement a Facebook share and like function with a callback. But it does not run the callback. And it was also not triggering the popup 2nd time it clicked.

I want to run a callback after the like and share event. And also I need to open a popup every time I click the share/like button.

Facebook Doc also goes to 404.

 <a>
  <div class="social_net_button facebook_button">
    <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";
          fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));

    </script>
    <div class="fb-like" data-href="https://facebook.com/MY_PAGE" data-send="false" data-layout="button_count" data-width="70" data-show-faces="false" data-action="like"></div>
  </div>
</a>







            $.getScript('//connect.facebook.net/en_US/sdk.js', function(){
            FB.init({
                      appId: "{{env('FB_SECRET_KEY')}}",
                      version: 'v2.8',
                      display: 'popup',
                      status : true,
                      xfbml  : true,
                      autoLogAppEvents: true
                    });
            FB.Event.subscribe('edge.create', function(response) {
                $.ajax({
                    url: '{{ URL("some-url") }}',
                    type: 'GET',
                })
                .done(function(response) {
                   toastr.info(response);
                })
                .fail(function() {
                    console.log("error");
                });
            });
        });

Solution

  • https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v15.0

    It seems that edge.create is deprecated, so there is most likely no way to get any feedback anymore.

    Btw, be aware that you are not allowed to reward users in any way for liking or sharing.