FB.getLoginStatus不起作用了吗?

5

对我来说,FB.getLoginStatus函数不起作用 - 尽管它曾经有一段时间可以使用。 以下是非常基本的代码,并且警报从未弹出 - 看起来像是FB.getLoginStatus从未调用提供的函数。 有什么想法吗?

<body>
<form id="form1" runat="server">
<div id="fb-root">
</div>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
    FB.init({ appId: 'xxx', status: true, cookie: true, xfbml: true });
    FB.getLoginStatus(function (response) {
        alert("Hi there");
    });
</script>
</form>

2个回答

6
如果您的应用程序处于沙盒模式,请查看此错误:https://developers.facebook.com/bugs/240058389381072。此外,请阅读Philip Bulley的评论。实质上,沙盒化应用程序对非应用程序开发人员是不可见的。如果没有用户当前登录到Facebook,Facebook将视为您的沙盒应用程序根本不存在(FB显然不知道您是应用程序开发人员,因此该应用程序是不可见的!)。此错误已得到确认和分配。

哦,天啊,感谢您的解释。我已经为了找出问题而苦思冥想了几个小时。关闭沙盒模式后,FB.getLoginStatus正常工作了。(这也质疑了沙盒模式的价值...但没关系)谢谢! - Jason A. Lefkowitz

0
你正在哪个平台上开发应用?如果是FBML,则检查FBJS-Facebook JavaScript。 我认为在FBML应用程序中警报不起作用。 我已经把这个工作做好了...只需要检查一下。
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
    FB.init({appId: 'APP_ID', status: true, cookie: true, xfbml: false});
};
(function() {
    var e = document.createElement('script');
    e.type = 'text/javascript';
    e.src = document.location.protocol +
        '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
}());
window.fbAsyncInit = function() {
     FB.init({appId: 'APP_ID', status: true, cookie: true, xfbml: true});

         /* All the events registered */
         FB.Event.subscribe('auth.login', function(response) {
             // do something with response
             login();
         });
         FB.Event.subscribe('auth.logout', function(response) {
             // do something with response
             logout();
         });

         FB.getLoginStatus(function(response) {
             if (response.session) {
                 // logged in and connected user, someone you know
                 login();
             }
         });
     };


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接