Question

I'm trying to execute callback function in FB.ui (send dialog). It called in same moment when loaded FB.ui but I want execute callback function after pressing 'send' or 'cancel' button. Is it realizable?

function callback(response) {
      alert('message was sent');
}

FB.ui({
                method: 'send',
                name: 'Dialog',
                link: 'http://***.com',
                redirect_uri: '****',
                description: '***',
                picture: '***',
                to: userId
            },
                callback(response)
            );
Was it helpful?

Solution

Yo, I'm not sure if it's your case, but it seems there's a bug when testing on development environments, mostly due an issue related to the port parameter in a url.

Check this out: http://developers.facebook.com/bugs/380566711996797

wasted like 2 hours freaking out due to this "bug"

OTHER TIPS

The callback requires a function as a parameter. Here, you are actually calling the function.

Facebook will actually call the function that you pass it along with the response.

Rather than passing "callback(response)" as the callback parameter, just pass "callback" like this:

function callback(response) {
      alert('message was sent');
}

FB.ui({
       method: 'send',
       name: 'Dialog',
       link: 'http://***.com',
       redirect_uri: '****',
       description: '***',
       picture: '***',
       to: userId
       },
       callback
);

Issue has probably been solved or is irrelevant to OP, but this might help some others out that stumble upon the post.

Similar to Mike Jerema's comment on Fisch's reply (Unable to comment there due to insufficient rep):

The response callback receive from the user interacting with the send dialog returns one of three things:

  1. If Send is clicked an empty array is passed back (instanceof Object)
  2. If Cancel is clicked null is returned
  3. If the 'X' in the corner of the dialog is clicked, undefined is returned.

Therefore the correct code to handle this callback for all use cases would be:

var callback = function(response) {
               if (response instanceof Object)
               {        
                   //Send clicked

                }
                else if (response === null)
                {
                    //Cancel clicked
                }
                else 
                    //X clicked
            };

Hope this helps! :)

This was driving me nuts for over 2 hours on the feed dialog, then as a last ditch I added the display property

method: 'feed',
display: 'popup'

This line isn't necessary as it is default, but maybe it forces the dialog to behave correctly, and it got me out of a hole. Worth a try on the send dialog?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top