How to detect user canceled share when using fb.ui

I am using the documentation provided here with the following code. The sharing dialog box is correct. The problem is that I cannot distinguish between the Undo and Publish actions that the user uses in the dialog box. I would suggest that this would be part of the answer.

FB.ui({
    method: 'share',
    href: 'https://developers.facebook.com/docs/',
}, function(response){
    if (response && !response.error_code) {
        console.log(response);
    } else {
        alert('Error while posting.');
    }
});

edit: console output gives no way to find out

Cancel - Object {e2e: "{"submit_0":1401181811121}"} 
Post - Object {e2e: "{"submit_0":1401181815112}"} 
+5
source share
4 answers

I tested this, and apparently there is some information in the object responsethat you could use to determine if the dialog box has been canceled.

the code

FB.ui({
    method: 'share',
    href: 'https://developers.facebook.com/docs/'
}, function(response){
    if (response && !response.error_code) {
        console.log("OK: "+JSON.stringify(response));
    } else {
        console.log("Not OK: "+JSON.stringify(response));
    }
});

:

{error_code: 4201, error_message: "User+canceled+the+Dialog+flow", e2e: "{"submit_0":1401188820613}"} 

, , :

FB.ui({
    method: 'share',
    href: 'https://developers.facebook.com/docs/'
}, function(response){
    if (response && !response.error_code) {
        console.log("OK: "+JSON.stringify(response));
    } else if (response && response.error_code === 4201) { //Cancelled
        console.log("User cancelled: "+decodeURIComponent(response.error_message));
    } else {
        console.log("Not OK: "+JSON.stringify(response));
    }
});

, FB.Events.subscribe() : https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.0

+4

, . , , , .

+2

"feed" "share", .

FB.ui({
    method: 'feed',
    caption: 'My Caption',
    link: 'http://www.google.com/'
}, function(response) {
    if (response && response.post_id) {
        alert('Thank you for sharing!');                
    } else {
        alert('You have cancelled the share.');
    }
});
+2

, fb.UI

    return FB.ui({
      method: 'share',
      href: this.shareUrl,
      hashtag: "myHashTag",
      quote: "myQuote"
    }, function(res) {
      console.log("res = ", res);
      console.log("res? = ", res != null);
      return App.vent.trigger("FBShareView:cancelled");
    });

I find that on a successful share, res is an empty array and res! = Null is true

I find that for the undo script res is undefined.

I expected to see res as an object with error_message, as described here: https://developers.facebook.com/docs/sharing/reference/share-dialog

Could you tell me what could be wrong?

+1
source

All Articles