Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is FB.UI Share response returning nothing?

I have setup a share popup triggered by Jquery. It works, but I want to use the response value to trigger an AJAX call on success and Facebook only returns an empty array.

Here is the javascript


    $("#fb-request").click(function () {
        FB.ui({
            method: 'share',
            name: 'Check out website',
            href: 'URL_TO_SHARE',
        },
        function (response) {
            if (response && !response.error_code) {
              console.log(response); // Returns: []
            }
        });
    });

Because of this I can't make the difference between someone who posts and someone who uses the cancel button. Am I missing something here? Or is there something to setup on the Facebook App?

Thanks,

like image 666
user1150316 Avatar asked Oct 01 '14 13:10

user1150316


2 Answers

From documentation:

Response Data

Parameter Description object_id Only available if the user is logged into your app using Facebook and has granted publish_actions. If present, this is the ID of the published Open Graph story.

like image 52
Daredzik Avatar answered Oct 16 '22 09:10

Daredzik


If the user cancels the share dialog, the response is undefined, so:

$("#fb-request").click(function () {
    FB.ui({
        method: 'share',
        name: 'Check out website',
        href: 'URL_TO_SHARE',
    },
    function (response) {
        if (response && !response.error_code) {
            if (typeof response != 'undefined'){
                //shered
            }
        }
    });
});
like image 36
Marcin Żurek Avatar answered Oct 16 '22 10:10

Marcin Żurek