Facebook登录按钮回调功能

MrT*_*uch 2 javascript facebook login facebook-graph-api

我的网站上的Facebook登录出现问题。下面的代码是我的FB连接代码。代码符号的注释部分使我进入了我的网站。我的问题是,当我“重新激活”此代码时,每次访问该页面时,它都会使我无法登录。但是我想在用户单击“使用Facebook登录”按钮时登录。当我单击Facebook登录按钮时,将显示一个弹出窗口,没有任何反应。

单击FB-Connect按钮时,可以通过某种方式调用JS函数吗?

              <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/');

                        }
                    });*/
                }});
Run Code Online (Sandbox Code Playgroud)

Ven*_*enu 5

您需要在单击fb connect按钮时使用FB.login函数,而不要使用FB.getLoginStatus

 FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  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.');
   }
 });
Run Code Online (Sandbox Code Playgroud)

从文件

FB.getLoginStatus允许您确定用户是否登录到Facebook并已验证您的应用程序。

因此,如果您不想检查用户是否已登录页面加载,则不要调用此功能

当我单击Facebook登录按钮时,将显示一个弹出窗口,没有任何反应。

如果您已经授权了该应用程序并通过了身份验证,facebook不会再次询问您登录和授权