【发布时间】:2011-04-07 10:59:28
【问题描述】:
我试图为我的 django 应用程序实现 facebook 注销功能。在我的应用中,用户可以使用应用用户名或 FB 用户名登录。现在我也想实现注销功能。 为此,我将此代码放在我的 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 >
【问题讨论】:
-
我认为您需要发布更多代码。您没有将 FB 传递给 logout 方法,也没有在 logout 方法中定义它。是全局变量吗?
-
对不起..除了“用户登录”的文字之外,这都是我的 html 中的所有内容。..我应该如何定义 FB?
-
抱歉我的无知..我对编程很陌生..
-
您正在调用方法 FB.getLoginStatus(arg)。这意味着 FB 必须引用具有这种方法的对象。除非您只是动态地发明方法名称,否则应该在某处定义此方法(以及它的对象)。 getLoginStatus 函数定义在哪里?
-
我已经在上面编辑了我的代码。我添加了一个 js 文件,我猜它包含了所有的 FB 方法。不过我不确定,现在你能解决我的疑问吗?我应该怎么做才能让它从这里开始工作。
标签: javascript python html django facebook