FB comments events comment.create and comment.remove not working

前端 未结 1 1000
没有蜡笔的小新
没有蜡笔的小新 2021-01-29 14:47

I am trying adding event listeners into my facebook comments. I tried probably everything I found here on Stack Overflow, also in FB developers docs and old developer forums. Co

相关标签:
1条回答
  • 2021-01-29 15:32

    I think you should reverse your code snippet because you are including the required javascript file after you are trying to initialize the FB Object.

    So the code should look like this

    <script>
    //INCLUDE THE SCRIPT FIRST
    (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={YOURAPPID}";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    
    
    //INITIALIZE THE OBJECTS
    window.fbAsyncInit = function() {
        FB.init({
            appId:  '{YOURAPPID}',
            status: true,
            cookie: true,
            xfbml:  true,
            oauth: true
        });
    
        //AND THOSE WILL FIRE THE EVENTS :)
    
        FB.Event.subscribe('comment.create',
            function (response) {
                console.log('create', response);
            });
        FB.Event.subscribe('comment.remove',
            function (response) {
               console.log('remove', response);
            });
    
    };
    
    0 讨论(0)
提交回复
热议问题