我的应用允许用户使用 Facebook 请求对话发送请求。
我按如下方式运行 init:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId: '193078857407882',
status: true,
cookie: true,
xfbml: false,
});
</script>
根据我在文档中的理解,'status: true' 应该检查用户是否登录到 facebook。
但是在我的应用程序中,当用户未登录时,它只会显示以下错误消息:
An error occurred with hbg. Please try again later.
如何强制应用程序检查用户是否登录,如果没有登录?
Rails 3.0.7、Ruby 1.9.2、Js SDK
最佳答案
根据 FB.getLoginStatus
的 Facebook 文档, 如果你想收到传递 status: true
到 FB.init
的响应, 那么你需要 subscribe
到 auth.statusChange
事件:
While you can call
FB.getLoginStatus
any time (for example, when the user tries to take a social action), most social apps need to know the user's status as soon as possible after the page loads. In this case, rather than callingFB.getLoginStatus
explicitly, its possible to check the user's status by setting thestatus: true
parameter with you callFB.init
.To receive the response of this call, you must
subscribe
to theauth.statusChange event
. The response object passed by this event is identical to that which would be returned by callingFB.getLoginStatus
explicitly.
所以在你的代码中你会做类似的事情
FB.Event.subscribe('auth.authResponseChange', function(response) {
alert('The status of the session is: ' + response.status);
});
除非您改为订阅 auth.statusChange
。但是请注意,根据 FB.Event.subscribe
文档:
auth.statusChange() does not have a 'status' field.
关于javascript - FB.INIT 即使状态为 :true js sdk 也不会强制登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7252484/