FB.getLoginStatus does not execute callback function

I have a difficult problem. Difficult means I searched through the network and StackOverflow, as well as all the documentation of the FBJS SDK and could not find the answer.

I am creating a Tab page application where I would like to allow fans to participate in rsvp events. So I have to check if the user is logged in, and if not, I need to log in. It sounds pretty simple, but FB.getLoginStatus does not perform a callback function. This is a code excerpt:

FB.init({ appId: window.appID, status: true, xfbml: true, cookie: true, oauth: true, channelUrl: 'http://example.com/fb/channel.html' }); 

and then I just - of course, after the user clicks the button - call FB.getLoginStatus, but it doesn't seem to do anything.

I already checked the sandbox mode, the success of FB.init, the URLs in the application settings and development environment. I can call FB.ui, although FB.ui with the method: "oauth" I get an error: "The parameter" redirect_uri "cannot be used in conjunction with the" next "parameter, which is deprecated.". This is very strange because I did not use the "Next" option. But when I install next to undefined, it works fine, I get a window, but it says: "This URL is not allowed by the application configuration." Expect me to be able to login, then I have access_token. But in the new window, getLoginStatus still does nothing.

Therefore, any advice is welcome.

Thanks Tamas

UPDATE :

 function onBodyLoad() { //on body onload FB.init({ appId: window.appID, status: true, xfbml: true, cookie: true, oauth: true, channelUrl: 'http://example.com/fb/channel.html' }); } ... function getName() { // on button onclick FB.getLoginStatus(function(response){ if (response.authResponse) { window.loggedIn = true; debugString('Logged in'); } else { window.loggedIn=false; debugString('Not logged in'); } }, true); if (window.loggedIn === undefined) { debugString('getLoginStatus did not exec'); // I always get this message } 

}

UPDATE 2 . I created a new application on a different url that is configured as a standalone website. There these codes work fine, I can getLoginStatus, I can log in, etc. Is there any difference working in the context of the FB and on a separate website using the FB JavaScript SDK?

+11
facebook facebook-oauth oauth facebook-graph-api
source share
6 answers

FB.getLoginStatus does not launch a callback when starting a website in another domain other than the one with which you registered the application. Usually I am in this situation when I am developing locally or on an intermediate server.

For example, if you registered a site with the example .com, and your intermediate server is example.mystagingserver.com, the callback will not start. In this case, you need to create a second application on Facebook and use the application identifier and secret for the new application.

+21
source share

I had the same problem, although this only happened to some users.

Finally, I found out that if your application is a sandbox mode, none of the developers can see your application as pagetab. But the call to getLoginStatus will fail (even turning on the log).

It took a while to realize that one of them, I hope this can save someone else some time.

+3
source share

I have been using this code successfully. I'm not quite sure where the differences are ... but I'm using the ASYNC FB bootloader.

  window.fbAsyncInit = function() { FB.init({ appId: 'XXXXXX', //change the appId to your appId status: true, cookie: true, xfbml: true, oauth: true}); function authEvent(response) { if (response.authResponse) { //user is already logged in and connected FB.api('/me', function(info) { login(response, info); }); } else { //user is not connected to your app or logged out button.onclick = function() { FB.login(function(response) { if (response.authResponse) { FB.api('/me', function(info) { login(response, info); }); } else { //user cancelled login or did not grant authorization } }, {scope:'email,rsvp_event,status_update,publish_stream,user_about_me'}); } } } // run once with current status and whenever the status changes FB.getLoginStatus(updateButton); FB.Event.subscribe('auth.statusChange', updateButton); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; document.getElementById('fb-root').appendChild(e); }()); function login(response, info){ if (response.authResponse) { accessToken = response.authResponse.accessToken; userid = info.id; userInfo.innerHTML = '<img src="https://graph.facebook.com/' + info.id + '/picture">' + info.name+"<br /> Your Access Token: " + accessToken; } } 
+2
source share

You can use the following code to check if the user is logged in:

 FB.getLoginStatus(function(response) { if (response.authResponse) { // logged in and connected user, someone you know } else { // no user session available, someone you dont know } }); 

From the FB JS SDK Documentation .

You can wrap all the code in jQuery ready:

 $('document').ready(function(){ ... above code }) 

You can also check out this StackOverflow question .

0
source share

I have the same problem. I worked on the process of logging into our site on Facebook. During development, "FB.getLoginStatus" did not return a response. I fixed this in the application settings on facebook:

-In facebook go to "manage applications"

-Go to the Facebook login settings of your application

-Add your development URL (for example, " https: // localhost ") to a "valid OAuth redirect URI"

(Remember to remove " https: // localhost " from the OAuth redirect URI when you're done.)

0
source share

After extensive testing, for me, you can confirm that the dialog for user registration will not be displayed if you are not using a valid Application ID

They can be found in

 https://developers.facebook.com/apps/{{Application__Id}}/settings/ 

Just make sure you call api with the correct id.

-one
source share

All Articles