我正在尝试退出我创建的集成了 Facebook 的网站。 登录工作正常,但是当我想注销时,Firebug 始终给我这个错误:
FB.logout()
在没有访问 token 的情况下调用。
我正在使用 Facebook JavaScript SDK,我必须注销的代码如下所示:
$(document).ready($(function () {
$("#fblogout").click(facebooklogout);
}));
function facebooklogout() {
FB.logout(function (response) {
}
)};
这是在 Facebook Developers Documentation 中指定的注销代码只需将按钮分配给 document.ready 上的方法
在这段代码之前,我有 FB.init()
方法,一切都运行良好。
如果有人知道为什么 FB.logout 没有访问 token 的解决方案,我们将不胜感激。
最佳答案
要从使用 facebook 图形 API 的应用程序注销,请在 <form>
之后的注销页面上使用此 JavaScript标签:
window.onload=function()
{
// initialize the library with your Facebook API key
FB.init({ apiKey: 'b65c1efa72f570xxxxxxxxxxxxxxxxx' });
//Fetch the status so that we can log out.
//You must have the login status before you can logout,
//and if you authenticated via oAuth (server side), this is necessary.
//If you logged in via the JavaScript SDK, you can simply call FB.logout()
//once the login status is fetched, call handleSessionResponse
FB.getLoginStatus(handleSessionResponse);
}
//handle a session response from any of the auth related calls
function handleSessionResponse(response) {
//if we dont have a session (which means the user has been logged out, redirect the user)
if (!response.session) {
window.location = "/mysite/Login.aspx";
return;
}
//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(handleSessionResponse);
}
代码有效并且在我的网站上有效。
关于javascript - FB.logout() 在没有访问 token 的情况下调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8430474/