gpt4 book ai didi

javascript - 登录我的应用程序后如何检测用户退出 Facebook?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:52:32 25 4
gpt4 key购买 nike

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

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'});

使用它时,人们可以在他们的墙上张贴:

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);

这工作正常,但有一个小问题。如果人们:

  1. 登录应用程序。
  2. 退出 Facebook。
  3. 尝试通过该应用制作墙贴。

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

我能否改为让 Facebook 向用户显示登录提示。或者我可以检测到错误并告诉用户他不再登录 Facebook 吗?

最佳答案

只需回想一下 getLoginStatus 但强制往返 Facebook。看下面的代码:

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

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

来自 JS SDK 文档:

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.

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.

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/)

关于javascript - 登录我的应用程序后如何检测用户退出 Facebook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9482876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com