WordPress.org

Forums

FB.Event.subscribe (1 post)

  1. fouldsy99
    Member
    Posted 1 year ago #

    I am struggling to get the FB.Event.subscribe working, I'm not received any notification when a user likes, comments or logins with facebook.

    Below is the code I have inserted in the header.php, does it look right?

    <div id="fb-root"></div>
    <script>  
    
    window.fbAsyncInit = function() {
        FB.init({
            appId  : 'appid',
            status : true, // check login status
            cookie : true, // enable cookies to allow the server to access the session
            xfbml  : true  // parse XFBML
        });
    
        /* All the events registered */
    
            FB.Event.subscribe('edge.create',
                        function (response) {
                            //console.log('edge.create');
                            alert('edge.create');
                        }
                 );
    
            FB.Event.subscribe('xfbml.render',
                    function (response) {
                        //console.log('xfbml.render');
                        alert('xfbml.render');
                    }
                 );
        };
    
        FB.Event.subscribe('comments.add', function (response) {
            // do something with response
            alert("comment added");
        });
    };
    
    FB.Event.subscribe('auth.authResponseChange', function(response) {
        if (response.status === 'connected') {
          console.log('Logged in');
        } else {
          FB.login();
        }
      });
    };
    
        FB.Event.subscribe('edge.create',
            function(response) {
                alert('You liked the URL: ' + response);
            }
        );
        FB.Event.subscribe('message.send',
            function(response) {
                alert('You sent the URL: ' + response);
            }
        );
    
    (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    }());
    
    (function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id; //js.async = true;
      js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId={566043900154048}";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    
    </script>

    Regards

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags