我有一个localhost网站和FB.logout()脚本。在执行了一些操作后,它无法将我注销,并且我在控制台中看到下一条错误消息:
Refused to display 'https://www.facebook.com/home.php' in a frame because it set 'X-Frame- Options' to 'DENY'.我搜索了所有的StackOverflow,没有找到任何有效的解决方案。Network inspector显示已取消near home.php查询。
所以我理解这个脚本试图在一个框架中加载Facebook主页,但它不能,因为它是被禁止的。那么我该如何修复它呢?为什么logout()不能为我工作?
我的代码
// Facebook Basic Example
window.fbAsyncInit = function() {
FB.init({
appId : '579651098766258',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
testAPI();
} else if (response.status === 'not_authorized') {
FB.login();
} else {
FB.login();
}
});
};
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
function testAPI() {
FB.api('/me', function(res) {
console.log(res);
setTimeout(function(){
FB.logout(); // <-- ERROR
}, 2000);
});
}发布于 2014-08-30 07:11:32
这个解决方案对我很有效:
我还制作了一个youtube视频来解决这个问题:https://www.youtube.com/watch?v=7CNpLgwa0-c

发布于 2018-08-25 19:46:20
我必须在Facebook的应用程序控制面板的设置选项卡中设置“应用程序域”字段才能正常工作:

发布于 2019-05-02 14:36:08
2019年5月2日之前更新:
1) https已强制生效,请务必使用https://localhost。http将不再可用。
2)您需要将本地主机列入白名单,方法是进入设置>基本>添加平台,然后选择“网站”
https://stackoverflow.com/questions/22331373
复制相似问题