简体   繁体   中英

Facebook button login issue (after successful login)

I am trying FB login for a site for first time. I am able to see the FB button and the popup window shows with what appears to be correct FB login with my app name, so i think that part is good. my issue is after clicking login I enter the user/pass, then window closes and nothing else happens. I know I am logged in because when i click the FB again it pops up and closes, so i guess it knows I am logged in to FB. but i cant see any of my calls to write to console, and I am not sure how to make it do something else after the loging... Maybe I am not understanding what happens after the login to FB is successful, am i missing something? . here is what I have tried so far.

    window.fbAsyncInit = function() {
          FB.init({
            appId      : 'XXXXXXXX', // App ID
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML
          });
    }

    function doLogin() {
    FB.login(function(response) {
       if (response.authResponse) {
         console.log('Hello!  Getting account information.... ');
         FB.api('/me', function(response) {
           console.log('Hello, ' + response.name + '.');
         });
       } else {
         console.log('User not fully authorize.');
       }
     });
    }
          // Load the SDK asynchronously
          (function(d){
           var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
           if (d.getElementById(id)) {return;}
           js = d.createElement('script'); js.id = id; js.async = true;
           js.src = "//connect.facebook.net/en_US/all.js";
           ref.parentNode.insertBefore(js, ref);
          }(document));

    function testFbLogin() {

        console.info("Testing you are Logged in...");

    }

In your FB app configuration there are settings for the domains and subdomains this app can use.

I guess you are trying to use the login from some development machine which name do not match the configured parameters for domains and subdomains for your FB app.

If you inspect the network communication (Crome developer tools are excellent and easy to use for this) you will see the error that FB returns and this will give you better idea what is going on.

If this is the case, then: Open /etc/hosts (unix) or C:\\WINDOWS\\system32\\drivers\\etc\\hosts. If your configured domain is example.com, then add this line:

127.0.0.1    dev.example.com

When you are testing, open dev.example.com in your browser and it should work.

As alternative you can edit your app at FB and set the "Site URL" to

http://localhost/myapppath or only http://localhost

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM