2010-05-18 72 views
24

我想在我的网站上使用新的Facebook图形API。这是我有:Facebook图形API:调用FB.init()之前调用FB.login()

某处在页面上:

<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> 

,但是当我点击生成的登录按钮,没有任何反应。

另外,我在Firebug的控制台获得

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

任何想法?

回答

41

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

它现在按预期工作。

更清晰我没有通过appId FB.init,一旦我做了,它的工作。

+1

这意味着,我没有传递一个关键FB.init方法。 – sabbour 2010-07-26 16:40:31

+0

我有同样的问题,但只有在MAC OSX的FF,它适用于所有其他浏览器。请帮助我。检查我的问题http://stackoverflow.com/questions/3338198/facebook-login-plugin-issue-with-ff-on-mac-osx – Nnp 2010-07-27 00:08:57

+1

你可以请发布整个工作代码。我在这里遇到同样的问题。谢谢 – Intellix 2011-02-03 12:13:39

2

对我来说,问题走了后,我禁用了XFBML功能(即xfbml项设置为false,去除fb:命名空间和<script src="…">#xfbml=1片段)。好,我不需要它。

YMMV,为什么会出现此错误消息还有其他几个有效的原因。

1

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

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