在Django应用中实现Facebook登出时出现FB未定义错误

0 投票
1 回答
1349 浏览
提问于 2025-04-16 15:16

我在为我的Django应用程序实现Facebook的登出功能。在我的应用中,用户可以用应用的用户名或者Facebook的用户名登录。现在我也想实现登出的功能。为此,我在我的HTML页面中放了这段代码,但我遇到了“FB未定义”的错误。有人能帮我解决这个问题吗?

<html xmlns:fb="http://www.facebook.com/2008/fbml">
 <div id="fb-root"></div>
 <script src="http://connect.facebook.net/en_US/all.js"></script>
 <script>
   FB.init({
     appId  : 'xxx',
     status : true, // check login status
     cookie : true, // enable cookies to allow the server to access the session
     xfbml  : true  // parse XFBML
   });
 </script>
    <script>

        function logout(){
            FB.getLoginStatus(handleFBSessionResponse);
            location.href = '/user_sessions/new';
        }

        // handle a session response from any of the auth related calls
        function handleFBSessionResponse(response) {
            /*
            //Check the facebook login status
            alert("handleFBSessionResponse(), "
             + "\nresponse.status="+response.status
             +" \nresponse.session="+response.session
             +" \nresponse.perms="+response.perms);
            */

            //if we do have a non-null response.session, call FB.logout(),
            //the JS method will log the user out
            //of Facebook and remove any authorization cookies
            FB.logout(handleFBSessionResponse);
        }


        </script>
        <a href="javascript:logout();">Logout</a >

1 个回答

0

我用这个方法搞定了

<a href="http://m.facebook.com/logout.php?confirm=1&next=http://10.1.0.90:8080/registrationForm" >Sign Out</a> 

撰写回答