Callback function with new Facebook Share button

facebook, facebook-events, facebook-javascript-sdk, facebook-widgets, javascript

Solution

The facebook share button has been deprecated in favor of the like button. From their docs:

The Share button has been deprecated in favor of the Like button, and will no longer be supported. Please use the Like button whenever possible to drive maximum traffic to your apps.

You can use the event with the like button, however if you want to track the shared button then it is still possible with some javascript. You can add a click event to your FB share button.

Here is an example I'm using.

window.fbAsyncInit = function () {
    FB.init({
        appId: 'your app id',
        status: true,
        cookie: true,
        xfbml: true,
        oauth: true
    });

    $('#facebook-share').click(function () {
        FB.ui({
            method: 'feed',
            link: document.URL,
            caption: 'example',
        }, function (response) {
            if (response === null) {
                console.log('post was not shared');
            } else {
                console.log('post was shared');
            }
        });
    });
};

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

Problem

I'm trying to subscribe to the "edge.create" event in conjunction with new Facebook Share button without any luck. I'm using the standard event subscription: ``` FB.Event.subscribe('edge.create', function(response) { console.log(response); } ); ``` The event is not fired... It works instead with the Like button Any suggestion?

Original source