如何在不刷新页面的情况下使用JS SDK从fb中注销 [英] how to detect log out from fb using JS SDK without refreshing the page

查看:108
本文介绍了如何在不刷新页面的情况下使用JS SDK从fb中注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

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

I'm developing a website in which Facebook Javascript API is used to send message to our friends.

当用户从fb注销时,然后在弹出js API对话框

When the user is logged out of fb,then it shows an error when popping up js API dialog box which is

"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'."

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

Currenty,I'm using FB.getLoginStatus to detect whether the user is logged out or not. But this will work for only first time,I can't dynamically check it(That means when I logged out of fb account and coming back to the same window and trying to send next message without refresh,it shows the above error.).

此处如何动态检测到用户当前已注销.有什么方法可以动态检查FB.getLoginStatus而无需刷新页面.

Here How Can I dynamically detect that the user is currently logged out. Is there any way to checking FB.getLoginStatus dynamically without page refresh.

我在下面显示我的代码.

I'm showing my code below.

$(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',因此会发生错误.

send_message(to,name); will send message if user is logged in, Currently for the first time,it works clearly,but from the second time without page refresh and if we logged out from fb, then FB.getLoginStatus still shows response.status as 'connected' and hence error occured.

等待您的答复. 在此先感谢

Waiting for your kind replies. Thanks in Advance

推荐答案

根据Facebook,

According to Facebook,

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

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

To improve the performance of your application, not every call to check the status of the user will result in request to Facebook's servers. Where possible, the response is cached. The first time in the current browser session that FB.getLoginStatus is called, or the JS SDK is init'd with status: true, the response object will be cached by the SDK. Subsequent calls to FB.getLoginStatus will return data from this cached response.

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

This can cause problems where the user has logged into (or out of) Facebook since the last full session lookup, or if the user has removed your application in their account settings.

要解决此问题,请调用FB.getLoginStatus,将第二个参数设置为true,以强制往返于Facebook,从而有效地刷新响应对象的缓存.

To get around this, you call FB.getLoginStatus with the second parameter set to true to force a roundtrip to Facebook - effectively refreshing the cache of the response object.

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

这篇关于如何在不刷新页面的情况下使用JS SDK从fb中注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆