Search code examples
javascriptfacebookfacebook-likefacebook-javascript-sdk

Facebook Callback not being triggered


I am trying to have a Facebook "like" trigger a callback, but it seems to either not work at all or work sporadically. Here is my code:

LIKE BUTTON HTML

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
<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=123456789";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="http://flevy.com/powerpoint-plugin" data-send="false" data-layout="box_count" data-width="50" data-show-faces="false"></div>

CALL BACK JAVASCRIPT

window.fbAsyncInit = function() {
    FB.init({appId:'123456789', status:true, cookie:true, xfbml:true});
    try {
        FB.Event.subscribe('edge.create', function(href, widget) {
            deliverEmail();
        });
    } catch (e) {}
};

I've also tried just this:

FB.Event.subscribe('edge.create', function(href, widget) {
    deliverEmail();
});

Here is the live version if you want to test it out: http://flevy.com/powerpoint-plugin

One other question. I created a Facebook app tied to the URL and am referencing its appID in the code. Is it necessary to do this--i.e. create a FB app for the page just to embed a "like" button?

Thanks.


Solution

  • edge.create is fired only when you use xfbml version of like button.

    Change

    <div class="fb-like" data-href="http://flevy.com/powerpoint-plugin" data-send="false" data-layout="box_count" data-width="50" data-show-faces="false"></div>
    

    to

    <fb:like href="http://flevy.com/powerpoint-plugin" send="false" layout="box_count" width="50" show_faces="false"></fb:like>