admin 管理员组

文章数量: 1086019

I got a Problem with the Facebook Login on my Website. The Code Below is my FB-Connect Code. The mented part of the code sign's me in to my Website. My Problem is when i "reactivate" this code it logs me in instandly everytime i visit the page. But i want to log the user in when he clicks the "Login with Facebook"-Button. When I clicks the facebook login button a Popup shows up and nothing happens..

Can i somehow call a JS function when i click the FB-Connect button?

              <script>
                    window.fbAsyncInit = function() {
                      FB.init({
                        appId      : 'xxxxxxxxxxxxxxxxxx', // App ID
                        status     : true, 
                        cookie     : true,
                        xfbml      : true,
                        oauth      : true,
                      });   
            var login = false;

                 FB.getLoginStatus(function(response) {
                          if (response.status === 'connected') {
                              console.log('connected');
                              login=true;

                                var uid = response.authResponse.userID;

            //this part of the code below redircts me to the part, where i login to my system.
                                /*var accessToken = response.authResponse.accessToken;
                                $.ajax({
                                    type: 'POST',
                                    url: '/?eID=login',
                                    data: $(this).serialize(),
                                    success: function(msg) { 
            alert("LOGIN");
                                $('#content').load('/live-session/tickets/');

                        }
                    });*/
                }});

I got a Problem with the Facebook Login on my Website. The Code Below is my FB-Connect Code. The mented part of the code sign's me in to my Website. My Problem is when i "reactivate" this code it logs me in instandly everytime i visit the page. But i want to log the user in when he clicks the "Login with Facebook"-Button. When I clicks the facebook login button a Popup shows up and nothing happens..

Can i somehow call a JS function when i click the FB-Connect button?

              <script>
                    window.fbAsyncInit = function() {
                      FB.init({
                        appId      : 'xxxxxxxxxxxxxxxxxx', // App ID
                        status     : true, 
                        cookie     : true,
                        xfbml      : true,
                        oauth      : true,
                      });   
            var login = false;

                 FB.getLoginStatus(function(response) {
                          if (response.status === 'connected') {
                              console.log('connected');
                              login=true;

                                var uid = response.authResponse.userID;

            //this part of the code below redircts me to the part, where i login to my system.
                                /*var accessToken = response.authResponse.accessToken;
                                $.ajax({
                                    type: 'POST',
                                    url: '/?eID=login',
                                    data: $(this).serialize(),
                                    success: function(msg) { 
            alert("LOGIN");
                                $('#content').load('/live-session/tickets/');

                        }
                    });*/
                }});
Share Improve this question edited Feb 21, 2013 at 13:44 holyredbeard 21.4k32 gold badges111 silver badges174 bronze badges asked Jun 4, 2012 at 14:41 MrTouchMrTouch 6542 gold badges12 silver badges29 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You need to use FB.login function on click on fb connect button and don't use FB.getLoginStatus

 FB.login(function(response) {
   if (response.authResponse) {
     console.log('Wele!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 });

From Doc

FB.getLoginStatus allows you to determine if a user is logged in to Facebook and has authenticated your app.

So, if you don't want to check whether user has logged in on page load, don't call this

When I clicks the facebook login button a Popup shows up and nothing happens..

If you had already authorized the app and authenticated, facebook wont ask you again for login and authorization

本文标签: javascriptFacebook Login Button callback functionStack Overflow