JMan
JMan

Reputation: 1805

Facebook JS SDK: FB.ui callback doesn't work - need working example code

When I use the Send dialog using the Facebook JS SDK FB.ui call, the callback does not trigger.

FB.ui(
      {
          method: 'send',
          to: ****,            // fbId 
          redirect_uri: *****, // public URL in my app domain 
          link: *****          // public URL 
      },
      function(response) {
          alert('callback was called!');
          if (response != null) {
               console.log('Request was passed along!');
               location.href= ***;    // just in case redirect_uri doesn't work
               return true;
          }
          else {
               console.log('Not passed along. User clicked cancel');
          }
      }

);

Expected behavior: The alert should be shown. The console message should be logged. And the user should be sent to the redirect_uri.

Actual Behavior: None of these 3 things happen. The Send dialog opens and the to: field is pre-populated correctly. When I click Send, it is sent correctly. But I need the callback to be triggered and the user needs to be sent to redirect_uri.

Upvotes: 4

Views: 7240

Answers (3)

Bharath Parlapalli
Bharath Parlapalli

Reputation: 75

Remove the redirect_uri item and the call back will be fired.

I was facing the same issue a few mins back and realized that removing the redirect_uri solved it.

Upvotes: 2

Rahul
Rahul

Reputation: 1505

Have you verified on other browsers? Check your browser settings once. Do you have an extension like "Facebook Disconnect" installed?

Upvotes: 0

Vijay
Vijay

Reputation: 5433

Every FB.UI has a callback function and it applies to Send dialog also.

See this document for general syntax for FB.UI.

But the problem is as other FB.UI methods, SEND method doesn't have a return value.

As per Facebook documentation ,

If sending the message is successful, the user will be redirected to the redirect_uri. Otherwise, an error will be shown. Unlike the Like Button, there is no return value per se.

So if the message sending is successful and you dont have a redirect_uri then the callback will have nothing as a return value and otherwise sends error when message sending is failed.

To confirm that callback is working use the following code,

FB.ui({
          method: 'send',
          name: 'People Argue Just to Win',
          link: 'http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html',
          },
          function(response){
           alert(response);
           if(response != null){
            alert('user clicked send');
           }else{
            alert('user clicked cancel');
           }
          });

when you click send and message is sent successfully , it will alert an empty string and when u click cancel it will alert 'null'.

Upvotes: 1

Related Questions