- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我按照 railscast 在我的站点中添加了“使用 Facebook 登录”功能,登录没有问题。但是当尝试注销时,即使我在 facebook 开发人员应用程序设置中禁用沙盒模式(如其他一些讨论中所建议的),FB.getLoginStatus 似乎也从未起火:
(function() {
jQuery(function() {
$('body').prepend('<div id="fb-root"></div>');
return $.ajax({
url: "" + window.location.protocol + "//connect.facebook.net/en_US/all.js",
dataType: 'script',
cache: true
});
});
window.fbAsyncInit = function() {
FB.init({
appId: 'xxxxxomittedxxxxx',
cookie: true,
status: true,
xfbml: true,
oauth: true
});
$('#sign_in').click(function(e) {
e.preventDefault();
return FB.login(function(response) {
if (response.authResponse) {
return window.location = '/auth/facebook/callback';
}
});
});
return $('#sign_out').click(function(e) {
FB.getLoginStatus(function(response) {
if (response.authResponse) {
return FB.logout(response.authResponse);
}
});
return true;
});
};
}).call(this);
我知道 FB.getLoginStatus 永远不会进入(或不起作用)的原因是我将正文替换为:
FB.getLoginStatus(function(response) {
return alert("I am here!");
});
点击“注销”时我看不到我的提醒。
我正在运行具有相同行为的 Chrome 和 Firefox。任何人都可以帮助发现我错过了什么吗?非常感谢。
让我更具体地描述一下我遇到的“行为”:
我希望我的网站表现:“当从 mysite.com/users/n 注销并再次从 mysite.com 使用 Facebook 登录时,将弹出 Facebook 登录窗口”
有人可以帮忙吗?非常感谢。
编辑:
进一步调查发现“根本”原因可能仍然是:注销在登录路由的不同路由(或页面)下,FB.getLoginStatus 无法在 mysite.com/signout 下触发。来自 firebug 的错误消息表明“应用程序配置不允许给定的 URL。应用程序的设置不允许一个或多个给定的 URL。它必须与网站 URL 或 Canvas URL 匹配,或者域必须是应用域之一的子域。”
为了证明这是路由问题,我将注销链接放在与登录路由相同的路由(页面)中,这是“使用 Facebook 登录的网站”中指定的根路由 mysite.com,一切正常并且可以按预期注销:
<%= link_to "sign out facebook", "#" , id: "sign_out" %>
顺便修改 sign_out js 以消除 FB.logout(response.authResponse) uncaught [object Object] 错误,因为 FB.logout 期望函数作为参数:
return $('#sign_out').click(function(e) {
FB.getLoginStatus(function(response) {
if (response.authResponse) {
FB.logout();
}
}, true);
});
};
因此,最重要的是:FB.getLoginStatus 可能仍然存在无法处理来自与登录路由不同的路由的调用的错误。 (我用 Chrome、Firefox 和 Safari 进行了测试,它们的行为都相同,但对于 IE10 则不然。不知何故,IE10 甚至可以在不同的路径上退出。)
有类似问题的人有什么意见吗?请指教。非常感谢您。
最佳答案
尝试将 true 作为第二个参数添加到 getLoginStatus,如 FB 开发文档中所述:
FB.getLoginStatus(function(response) {
// this will be called when the roundtrip to Facebook has completed
}, true);
这应该避免缓存。另一种选择是订阅事件:
FB.Event.subscribe('auth.login', function(response) {
// do something with response
});
全部来自here
如果您有任何问题,请发表评论。
编辑:
我稍微修改了你的脚本,删除了不需要的代码部分。您有太多不需要的返回。我尝试在这个修改后的脚本中注销,它可以按你的需要工作。事件订阅用于检查目的。
<head>
<title>Exam entry</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<div id="fb-root"></div>
<input type="button" value="Sign in" id="sign_in" />
<input type="button" value="Sign out" id="sign_out" />
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({
appId: '586844044669652',
cookie: true,
status: true,
xfbml: true
});
// Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
// for any authentication related change, such as login, logout or session refresh. This means that
// whenever someone who was previously logged out tries to log in again, the correct case below
// will be handled.
FB.Event.subscribe('auth.authResponseChange', function (response) {
// Here we specify what we do with the response anytime this event occurs.
if (response.status === 'connected') {
// The response object is returned with a status field that lets the app know the current
// login status of the person. In this case, we're handling the situation where they
// have logged in to the app.
testAPI();
} /*else if (response.status === 'not_authorized') {
// In this case, the person is logged into Facebook, but not into the app, so we call
// FB.login() to prompt them to do so.
// In real-life usage, you wouldn't want to immediately prompt someone to login
// like this, for two reasons:
// (1) JavaScript created popup windows are blocked by most browsers unless they
// result from direct interaction from people using the app (such as a mouse click)
// (2) it is a bad experience to be continually prompted to login upon page load.
FB.login();
} else {
// In this case, the person is not logged into Facebook, so we call the login()
// function to prompt them to do so. Note that at this stage there is no indication
// of whether they are logged into the app. If they aren't then they'll see the Login
// dialog right after they log in to Facebook.
// The same caveats as above apply to the FB.login() call here.
FB.login();
}*/
});
$('#sign_in').click(function (e) {
e.preventDefault();
FB.login(function (response) {
if (response.authResponse) {
//return window.location = '/auth/facebook/callback';
}
});
});
$('#sign_out').click(function (e) {
FB.logout(function (response) {
console.log("Here logout response", response);
});
});
};
// Here we run a very simple test of the Graph API after login is successful.
// This testAPI() function is only called in those cases.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function (response) {
console.log('Good to see you, ' + response.name + '.');
});
}
// Load the SDK asynchronously
(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));
</script>
</body>
关于javascript - FB.getLoginStatus 在 Chrome 中不起作用,即使沙盒禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17478429/
我有问题,我想在那个应用程序中使用 FB 好友列表,我可以通过 FB SDK 检索 FB 好友列表...... 最佳答案 FB SDK 支持通过以下方式调用 FB graph api: - (FBRe
我有一个简单的视频,最后包含一个共享按钮,当用户单击共享按钮时,会打开一个带有社交媒体图标的模态框,例如用户可以将视频共享到 Facebook,现在我想要来自 Facebook 的回调响应视频分享后。
我收到常见的 JS 错误“ Uncaught ReferenceError :未定义 FB” 关于同一个问题有很多问题,我已经尝试了每个可用的解决方案 stackoverflow 但无济于事。显然,人
你好,我想知道如果我创建了一个 Facebook 页面(没有普通用户)是否可以获得 FB APP_ID,或者这个 ID 仅用于应用程序?谢谢 最佳答案 如果您是 Facebook 用户,请登录您的 I
我有一个客户已经有一个与他们自己的网站相关联的 Facebook 页面。我最终说服他们将开放图标签集成到他们的页面中,因为当任何人点击他们网站上的 Facebook Like 按钮时,它在 Faceb
我的问题很简单,FB Messenger如何知道谁与其他FB应用程序连接,我的意思是在iOS中,应用程序使用sandBox,但是当您在“正常”应用程序中作为“xy”连接并且打开Messenger时它会
这段最近工作完美的代码在与 FB JS API 一起使用时不再正常工作: placeOrder : function(order_info) { var onOrderPlaced = funct
我正在尝试从我使用以下代码的 facebook 广告 api 获取广告系列列表 $account = new AdAccount('act_' . $account_id);
我的控制台中有这条消息 FB.getLoginStatus() called before calling FB.init(). 我的代码 // Load the SDK Asyn
我知道有很多关于 Facebook 访问 token 的问题及其造成的痛苦,但尽管进行了大量实验并阅读了许多令人沮丧的模糊博客文章(FB 和其他),我仍在努力获得明确的答案根据我的需要。让我简要地分解
我查看了有关 stackoverflow 的各种文档和问题,但仍然无法弄清楚为什么以下代码不会触发任何 FB.Event.subscribe 事件 getLoginStatus。 (fun
我想要实现的是: 我有一个简单的 Facebook 分享按钮,取自 Facebook 开发人员。站点: 现在我在开始正文标记之前添加了同样取自 facebook 的 facebook 应用程序代码:
我想检查用户是否使用 Facebook JavaScript JDK 和 jQuery 登录 facebook。但即使超时 10 秒,我也会收到此错误消息: 在调用 FB.init() 之前调用 FB
我有一个正在编写的网站。 javascript SDK 有效 php SDK 有效 HTML 如下所示: 带有 fb-registration div 的注册页面 带有 fb-login-button
我正在尝试检查用户是否已使用我的应用登录,但我收到了 FB.getLoginStatus() called before calling FB.init(). 控制台出错。 setSize似乎有效(虽
FB.api 在 FB.init 之后立即调用时不起作用。这是我使用的代码片段: window.fbAsyncInit = function() { FB.init({ appId : w
我希望用户在单击我网页上的几个按钮之一时能够将一些图像发布到他们的 Facebook 页面。 FB.getLoginStatus(function(response) { if ( respon
我正在使用 PFFacebookUtils.logInWithPermissions 登录我的应用程序,但是,第一次登录实际登录工作正常,但出现 FB 错误 code = 2500 An active
我全新的工作充满了美妙和可怕的惊喜。这项工作最有趣的部分之一是增强、加速、使一切规模化的意愿。今天,第一个真正的问题。事情是这样的:我们得到最多 20 个列表元素,每个元素都显示自己的 Faceboo
我在这里使用 asp.net web 应用程序,我在我的网页中使用 2 个 facebook 插件。 Facebook 赞 Facebook 分享 对于 facebook 分享: Faceboo
我是一名优秀的程序员,十分优秀!