登录我的应用程序后如何检测用户登出Facebook? [英] How to detect user logging out of Facebook after logging into my app?

查看:185
本文介绍了登录我的应用程序后如何检测用户登出Facebook?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用Facebook验证:

My application uses Facebook authentication:

FB.init({

    appId: config.fbAppId,
    status: true,
    cookie: true,
//  xfbml: true,
//  channelURL : 'http://WWW.MYDOMAIN.COM/channel.html', // TODO
    oauth  : true

});

// later...

FB.login(function(response)
{
    console.log(response);
    console.log("authId: " + response.authResponse.userID);
    gameSwf.setLoginFacebook(response.authResponse.accessToken);
}, {scope:'email,publish_actions,read_friendlists'});

使用它时,人们可以发布到他们的墙上:

And when using it, people can post to their wall:

var obj = {
      method: 'feed',
      link: linkUrl,
      picture: pictureUrl,
      name: title,
      caption: "",
      description: message
    };

    function callback(response) {
      // console.log("Post on wall: " + response);
    }

    FB.ui(obj, callback);

这工作正常,但有一个小小的笨蛋。如果有人:

This works fine, but there is one little hickup. If people:


  1. 登录该应用。

  2. 退出Facebook。 >
  3. 尝试从应用程序中发布墙壁信息。

打开墙上的对话框失败。控制台说拒绝显示文档,因为X-Frame-Options禁止显示

The opening of the wall post dialog fails. The console says "Refused to display document because display forbidden by X-Frame-Options.".

我可以让Facebook显示一个登录提示给用户。或者我可以检测到错误,并告诉用户他不再在Facebook上登录?

Can I instead get Facebook to show a login prompt to the user. Or can I detect the error and tell the user that he's no longer logged in on Facebook?

推荐答案

回想起 em> getLoginStatus ,但强制往返于Facebook。看看以下代码:

Just recall getLoginStatus BUT forcing a roundtrip to Facebook. Look following code:

FB.getLoginStatus(function(response) {
  // some code
}, true);

查看最后一个参数设置为 强制往返。

Look the last parameter set to true to force the roundtrip.

从JS SDK文档:


您的应用程序的性能,而不是每次调用
检查用户的状态将导致请求到Facebook的
服务器。在可能的情况下,响应缓存。在
当前浏览器会话中,首次调用了 FB.getLoginStatus ,或者JS
SDK的初始状态为true:响应对象将被缓存
的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的往返路线 - 有效地
刷新响应对象的缓存。
http://developers.facebook.com/docs/reference /javascript/FB.getLoginStatus/

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. (http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/)

这篇关于登录我的应用程序后如何检测用户登出Facebook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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