Search code examples
javascriptfacebookfacebook-javascript-sdkfacebook-comments

Facebook event subscription 'comment.create' not working


OK, so I'm trying to save each comment that is being made in the facebook comments widget locally for later use. I subscribe to both the 'comment.create'- and 'comment.remove'-event - which in turn should fire my 'fb_fetch_comment'-function. However, 'comment.create' never fires. The weird thing is that the problem only occurs with 'comment.create' - and not 'comment.remove' - which works just as it should.

I have implemented the following code in my html:

<div class="fb-comments" data-href="<?php echo get_permalink(); ?>" data-numposts="25" data-width="100%"></div>

Then i include the js in a separate file. The code is as follows:

(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/nb_NO/sdk.js#xfbml=1&version=v2.4&appId={MY-APP-ID}";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

window.fbAsyncInit = function() {
  FB.init({
    appId      : {MY-APP-ID},
    xfbml      : true,
    version    : 'v2.4'
  });

  FB.Event.subscribe('comment.create',function(comment_data){
    fb_fetch_comment(comment_data, 'create') 
  });
  FB.Event.subscribe('comment.remove',function(comment_data){
    fb_fetch_comment(comment_data, 'remove') 
  });
  function fb_fetch_comment(comment_data, comment_action) {
    jQuery.post(
        fb_ajax.url, { 
            commentid: comment_data.commentID, 
            security: fb_ajax.security,
            action: 'fb_ajax_update_comment',
            event: comment_action,
            url: comment_data.href
    });
  }
};

Any ideas where the problem may lie?


Solution

  • The issue has resolved itself without any action taken on my part. Must have been an error in Facebooks own API. Case closed.