4

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.

JMan
  • 1,815
  • 5
  • 21
  • 34
  • Hey, any chance we could get a link? This might sound stupid, but are you sure that the console is active in the browser you're using? What happens if you console.log(response)? – Claudiu Mar 20 '12 at 12:47
  • Are you sure message sent correctly? – Somnath Muluk Mar 21 '12 at 05:05
  • The console is active and the message is sent correctly. – JMan Mar 22 '12 at 16:26
  • This is a known bug. See: https://github.com/davejohnson/phonegap-plugin-facebook-connect/issues/118 – keune Jun 22 '12 at 15:40
  • It seems that 'redirect_uri' conflicts with callback! It works if 'redirect_uri' is not specified. But you have to specify proper 'Site URL' in application settings. Here's the great discussion: http://stackoverflow.com/questions/4691782/facebook-api-error-191 – rudyryk Aug 01 '12 at 09:55

3 Answers3

2

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.

j0k
  • 22,600
  • 28
  • 79
  • 90
1

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'.

Vijay
  • 5,331
  • 10
  • 54
  • 88
  • I used your code, but it still doesn't work. None of the alerts pop open. I also included a redirect_uri, but FB doesn't redirect there. My website is in sandbox mode, but this shouldn't be a problem. Other solutions? – JMan Mar 18 '12 at 01:29
  • The send dialog needs the link to be an active url which is accessible to the world. For testing purpose use any publicly available domain. – Vijay Mar 18 '12 at 17:19
  • Yes, the link is publicly available and in the domain specified in the FB dev app. But the user is still not sent to the redirect_uri. Other solutions? – JMan Mar 19 '12 at 02:37
0

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

Rahul
  • 1,495
  • 1
  • 15
  • 25