Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook login without pop-up?

I'm trying to make a simple facebook app, but for the authorization, it seems that it's always blocked by a popup-blocker. My code is thus:

FB.init({
        appId  : THEAPPPIDDDD,
            status : true,
            cookie : true,
            xfbml  : true,
   });


FB.login(function(response) {
           if (response.authResponse) {
               FB.api('/me', function(response) {
               FB.logout(function(response) {
                               console.log('Logged out.');
                           });
                   });
           } else {
               console.log('User did not authorize.');
           }
       });

Any help would be greatly appreciated... thanks

like image 852
Dave Zhang Avatar asked Aug 19 '11 17:08

Dave Zhang


People also ask

How do I bypass Facebook login prompt?

Attention: Viewing Facebook without an Account, you can simply bypass the Facebook “Log In or Sign Up” prompt by clicking on the “Not Now” link at the bottom of the page.

How do I use OAuth on Facebook?

In the App Dashboard, choose your app and scroll to Add a Product Click Set Up in the Facebook Login card. Select Settings in the left side navigation panel and under Client OAuth Settings, enter your redirect URL in the Valid OAuth Redirect URIs field for successful authorization.


2 Answers

I aware that this question is a possible duplicate of another question: Stop the facebook popup blocker I am reposting this to help Dave Zhang. I have adapted this code for one of my site. In the following code, replace the YOUR_APP_ID and your website url, then the Facebook login will be popup-less.

//Javascript
var uri = encodeURI('http://example.com');
FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
        window.location.href=uri;
    } else {
        window.location = encodeURI("https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri="+uri+"&response_type=token");
    }
});

This will just redirect directly instead of opening a pop-up.

like image 185
Y P Avatar answered Oct 10 '22 16:10

Y P


You should initiate your login code on click of some button. As a good practice while dealing with FB, the login process should always be initiated by user.

Call your code on click of a button and it should FIX your problem.

like image 33
Purusottam Kaushik Avatar answered Oct 10 '22 15:10

Purusottam Kaushik