Facebook login without pop-up?

前端 未结 5 1106
一向
一向 2020-12-08 08:18

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({
              


        
相关标签:
5条回答
  • 2020-12-08 08:50

    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.

    0 讨论(0)
  • 2020-12-08 08:51

    to avoid doing the login via a popup, you should kick off the authentication at the server side

    0 讨论(0)
  • 2020-12-08 09:00

    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.

    0 讨论(0)
  • 2020-12-08 09:13

    Small update for this old question which I found very useful, I was keep getting error which the domain is not allowed and it was allowed:

    Can't Load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings.

    so, after small research I discovered you have to change your facebook app setting to allow such navigation:

    1. enforce HTTPS
    2. Use Strict Mode for redirect URIs
    3. Embedded Browser OAuth Login (In case you use app webview)
    0 讨论(0)
  • 2020-12-08 09:14

    The popup blocker will always initiate if the Popup action did not originate in an event caused by a user. For example, if you try and do a popup on a load event, the browser will most likely use the popup blocker. On the other hand, if you trigger the popup on a click event or keydown event, it is less likely that the popup blocker will be triggered.

    You could also employ a method that has your application detect whether or not the popup was blocked. You can read more about that here.

    As mentioned in other answers, if you'd rather do the authentication process without popups at all, you would need to handle this at the server side using OAuth.

    0 讨论(0)
提交回复
热议问题