Facebook login window appears and disappears very quickly

I recently uploaded a code snippet to phpfog, and I ran into a problem that didn't happen locally:

When the page loads, it tries to get $ idFacebook, which must be installed:

$idFacebook = $facebook->getUser(); if ($idFacebook) { ... } 

I registered on Facebook, but the condition does not work, and a button appears to enter:

 <div class="fb-login-button" data-scope="user_likes,user_photos"></div> 

Another problem is that when I click the button, it seems that the login window appears, but it automatically closes very quickly.

My code is basically the same as Heroku when you create the Facebook app. The repository is: https://github.com/heroku/facebook-template-php . I canโ€™t find how to solve it, and I saw that many people had several problems logging into facebook.

I look forward to helping you. Thanks in advance.

+3
javascript php facebook facebook-login
source share
4 answers

My actual error was that $ facebook-> getUser () returned 0 because the application was not authenticated and the application was not authenticated because I moved my code from the host to another in another domain and I forgot to change the configurations applications at http://developers.facebook.com .

Now the application is automatically registered. Thanks everyone!

+4
source share

The login window quickly disappears, checking if you need to grant permissions for the application or not. It closes almost instantly because you are already logged in and logged in using Facebook.

I am not familiar with Heroku / Facebook integration, but I assume that the problem with $idFacebook is due to the wrong configuration.

+1
source share

The login window quickly disappears because you can login to facebook in the same browser.

I am not familiar with Heroku, but I overcame this problem in Zend Framework - php. I used javascript-sdk to login and logout. You can refer to this link.

http://developers.facebook.com/blog/post/2011/07/21/updated-javascript-sdk-and-oauth-2-0-roadmap/

So, when you implement this example in your code, it will ask you to log out when you log in to FB in the same browser. so when you click logout it will again ask you to log in and thats it.

Hope this helps.

+1
source share

To avoid this, you need to slightly modify the behavior of your facebook script using FB.getLoginStatus. It checks if the user is already registered on Facebook, and if he has already allowed your application.

 FB.getLoginStatus(function(response) { if (response.status === 'connected') { window.location = //redirect to page with logged user (you have the response token in response) } else { //Show the login popup FB.login(function(response) { if (response.authResponse) { window.location = //redirect to location after correct login } }, { scope: '<scopes>', state: '<state>' }); } }); 

Thus, if the user is "connected" (authorized and registered in the application), you will not call the FB.login method, so the login window will not blink. In any other case, it will show the login window, which is the expected result.

Check out the https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus full documentation.

0
source share

All Articles