25

我正在尝试在我的网站上使用新的 Facebook Graph API。这就是我所拥有的:

页面某处:

<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button>

在标签之后:

<div id="fb-root">
    </div>
    <script type="text/javascript">
        window.fbAsyncInit = function () {
            FB.init({ appId: '<%= ConfigurationManager.AppSettings["FBAppId"] %>', status: true, cookie: true, xfbml: true });

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

            FB.getLoginStatus(function (response) {
                if (response.session) {
                    // logged in and connected user, someone you know
                    alert("login success");
                }
            });
        };
        (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>

但是当我点击生成的登录按钮时,什么也没有发生。

另外,我得到

FB.getLoginStatus() called before calling FB.init().

在 Firebug 控制台中。

有任何想法吗?

4

3 回答 3

45

我不敢相信,我在 Web.config 中引用了一个不存在的键,因此 FB.init 默默地失败了。

它现在按预期工作。

更清楚地说,我没有将 appId 传递给 FB.init,一旦我这样做了,它就起作用了。

于 2010-05-18T09:24:42.570 回答
3

有同样的问题,这是对我有用的解决方案。只需将以下内容放在您的 head 部分中,或者换句话说,将app_id添加到 facebook js 的源代码中。

<script src="//connect.facebook.net/en_US/all.js&appId=xxxxxxxxxxxxxxx" type="text/javascript"></script>

于 2015-02-19T07:32:29.170 回答
2

就我而言,在我禁用 XFBML 功能后问题就消失了(即将xfbml密钥设置为false,删除fb:名称空间和 中的#xfbml=1片段<script src="…">)。很好,反正我也不需要它。

YMMV,出现此错误消息还有其他几个正当原因。

于 2011-08-24T14:30:32.233 回答