Facebook JS SDK: FB.ui callback not working - need a working code example

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

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: A warning should be shown. A console message must be logged. And the user must be sent to redirect_uri.

Actual behavior: None of these three things happen. The "Submit" dialog box opens, and the ":" field is pre-populated. When I click "Submit", it is sent correctly. But I need to call a callback, and the user must be sent to redirect_uri.

+4
source share
3 answers

Remove the redirect_uri element and the call will start.

I ran into the same question a few minutes ago and realized that removing redirect_uri solved it.

+2
source

Each FB.UI has a callback function, and it also applies to the dialog box.

See this document for general syntax for FB.UI.

But the problem is that other methods are FB.UI, the SEND method has no return value.

According to the documentation on Facebook,

If the message is sent successfully, the user will be redirected to redirect_uri. Otherwise, an error will be shown. Unlike the Like button, it is missing by itself.

So, if the message was sent successfully and you do not have redirect_uri, then the callback will not have anything as a return value and, otherwise, it will send an error message when sending the message.

To confirm that the 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 the message is sent successfully, it will warn an empty line and when you click "Cancel", the warning "null" is issued.

+1
source

Have you checked other browsers? Check your browser settings once. Do you have an extension, such as "Disable Facebook "?

0
source

Source: https://habr.com/ru/post/1401923/


All Articles