如何使用JS SDK检测从fb注销而不刷新页面

嗨朋友们,

我正在开发一个网站,其中使用Facebook Javascript API向我们的朋友发送消息。

当用户退出fb时,弹出js API对话框时显示错误

"Refused to display 'https://www.facebook.com/login.php?api_key=0&skip_api_login=1&display=dialo…cale%3Den_US%26name%3DAnything%26to%3D1791715188%26from_login%3D1&rcount=1' in a frame because it set 'X-Frame-Options' to 'DENY'."

Currenty,我正在使用FB.getLoginStatus来检测用户是否已注销。 但这只能第一次工作,我无法动态检查它(这意味着当我退出fb帐户并回到同一个窗口并尝试发送下一条消息而不刷新时,它会显示上述错误。)。

这里如何动态检测用户当前是否已注销。 有没有办法动态检查FB.getLoginStatus没有页面刷新。

我在下面显示我的代码。

 $(document).ready(function(){ window.fbAsyncInit = function() { FB.init({appId: '**************', xfbml: true, cookie: true,status:true,oauth:true}); /*FB.Event.subscribe('auth.login', function() { //window.location.reload(); });*/ FB.Event.subscribe('auth.logout', function(response) { alert('logged out!'); }); }; function facebook_send_message(to,name) { //function called when a button is clicked FB.getLoginStatus(function(response) { if (response.status === 'connected') { console.log('how to check'); var uid = response.authResponse.userID; var accessToken = response.authResponse.accessToken; send_message(to,name); } else if (response.status === 'not_authorized') { console.log('not_authorized'); // the user is logged in to Facebook, // but has not authenticated your app } else { console.log('hi'); FB.login(function(response) { if (response.authResponse) { send_message(to,name); //getUserInfo(); // Get User Information. } else { console.log('Authorization failed.'); } },{scope: 'email'}); } }); } 

send_message(to,name); 如果用户登录将发送消息,目前这是第一次,它工作清楚,但从第二次没有页面刷新,如果我们从fb退出,那么FB.getLoginStatus仍显示response.status'connected' ,因此发生了错误。

等待你的回复。 提前致谢

根据Facebook,

https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

为了提高应用程序的性能,并非每次检查用户状态的调用都会导致对Facebook服务器的请求。 在可能的情况下,缓存响应。 在当前浏览器会话中第一次调用FB.getLoginStatus,或者JS SDK初始化为status:true,响应对象将由SDK缓存。 对FB.getLoginStatus的后续调用将从此缓存的响应中返回数据。

这可能会导致用户自上次完整会话查询以来登录(或退出)Facebook的问题,或者用户已在其帐户设置中删除了您的应用程序。

为了解决这个问题,你可以调用FB.getLoginStatus并将第二个参数设置为true来强制往返于Facebook – 有效地刷新响应对象的缓存。

 FB.getLoginStatus(function(response) { // this will be called when the roundtrip to Facebook has completed }, true);