FB.getLoginStatus()不起作用 [英] FB.getLoginStatus() not working

查看:217
本文介绍了FB.getLoginStatus()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个代码来检查用户是否已登录,
并发现FBJS API中有一个内置方法,称为getLoginStatus()

I am trying to write a code that checks whether the user is logged in or not, and found that there is a built-in method in FBJS API, which is called getLoginStatus()

我已经在html,
中实现了它但是对于某些方法,getLoginStatus()内部的alert()没有被触发。

I have implemented it inside of html, but for some how, alert() inside of the getLoginStatus() is not fired.

我也试过在init()中添加channelUrl,但它仍然是这样做的。

I have also tried to add channelUrl at init(),but it still does the same.

以下是我写的代码。

任何人都可以帮我吗?

提前致谢!

<!-- Initialize FB API for use -->
    <div id="fb-root"></div>
    <script type="text/javascript"> 
    //var curLoc = window.location;
    //var chanURL = curLoc.protocol + "//" + curLoc.hostname + ":" + 
    //curLoc.port + "/channel.html"


        window.fbAsyncInit = function() {
            FB.init({appId: '####', status: true, cookie: true, xfbml: true});       

            FB.getLoginStatus(function(response) {
                  if (response.session) {
                    // logged in and connected user, someone you know
                    alert('logged in');
                  } else {
                    // no user session available, someone you dont know
                    alert('not logged in');
                  }
            });
        };
        (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);
        }());
    </script>


推荐答案

前几天我有这个,问题是那个我没有登录Facebook而我的应用程序处于沙盒模式。 Maaaaybe在这里也是一样,但是想要建议它。

I had this the other day and the problem was that I was NOT logged in in Facebook AND my App was in Sandbox mode. Maaaaybe it's the same here, longshot but wanted to suggest it anyway.

注意:无法使用的可比组合正在Facebook中作为测试用户登录无法访问相关应用程序或以非测试/非管理员用户身份登录Facebook并使应用程序处于沙箱模式。

Note: Comparable combinations that wouldn't work are being logged in in Facebook as a Test user that has no access to the application in question or being logged in in Facebook as a non-test/non-admin user AND having the app in sandbox mode.

这篇关于FB.getLoginStatus()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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