如果用户未登录Facebook,则在FB.init期间不会触发auth.statusChange [英] auth.statusChange doesn't fire during FB.init if the user isn't logged in to facebook

查看:63
本文介绍了如果用户未登录Facebook,则在FB.init期间不会触发auth.statusChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人找到了我所遇到的行为的解决方法.

I wondered if anyone has found a workaround to the behaviour that I'm experiencing.

以下面的代码为例:

<script>
window.fbAsyncInit = function() {
        FB.init({
          appId      : '[----removed-------]', // App ID
          channelUrl : 'http://localhost/channel.html', // Channel File
          status     : true, // check login status
          cookie     : true, // enable cookies
          xfbml      : true  // parse XFBML
        });     
        // Additional initialization code here

        FB.Event.subscribe('auth.statusChange',fbLoginStatus);

        console.log("getloginstatus");

        FB.getLoginStatus(fbLoginStatus);
</script>

使用状态设置为true的FB.init,实际上根据表面上预期的行为触发事件 auth.statusChange ,因为默认值为未知",所以的未登录"值也为未知"(即使可以知道!)

Using FB.init with status set to true, essentially calls getLoginStatus() according to the facebook documentation. However, it is apparently intended behaviour that this will not trigger the event auth.statusChange, because the default value is 'unknown', and the value for 'not logged in' is also 'unknown' (even though it can be known!!)

因此,如果我还想回复那些对以下内容感兴趣的用户,则必须显式地调用 FB.getLoginStatus() ,以及将的状态设置为true没有登录到Facebook.

Therefore I have had to make a call to FB.getLoginStatus() explicitly as well as having the status set to true if I want to also respond to users who are not logged in to facebook.

问题是,如果用户不是注销"用户,这将导致该函数被调用两次.

The problem is, this results in the function being called twice if the user is anything other than "logged out".

是否有一种巧妙的方法可以阻止这种情况的发生?我认为我唯一的选择可能是调用一个不同的函数来处理auth更改事件.

Is there a neat way to stop this happening? I think my only option might be to call a different function to handle auth change events..

推荐答案

为此,我最好的解决方案是在fb.init选项中将状态设置为"false",然后分别显式调用getloginstatus.

My best solution for this was to set status to 'false' in the fb.init options, then to explicitly call getloginstatus separately.

IF get loginstatus以未知(即注销)的身份返回,我订阅了状态更改事件,并按照通常的方式显示登录按钮.然后,当用户登录时,状态更改将按预期触发.

IF get loginstatus came back as unknown (i.e. logged out), I subscribed to the status change event, as well as doing the usual of displaying the login button. Then when the user logs in, status change fires as expected.

这篇关于如果用户未登录Facebook,则在FB.init期间不会触发auth.statusChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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