1

我的网站上使用 xfbml 和 fbjs 有两种不同的机制:

  • 单个条目的 FB:Like 标签
  • 使用 fb connect 进行 facebook 登录的 FB 对象

我的问题是当我在页面上包含“all.js”时,登录脚本有效,但 fb:like 标记无效。

当我包含“all.js#xfbml=1”时,fb:like 标签再次起作用,但现在我的 FB 对象未定义并且我的登录代码不起作用。

有什么我想念的吗?

提前感谢您提供的任何帮助。

4

2 回答 2

1

您只需要包含一次脚本引用,并在页面加载时在脚本上调用 init。您可以将其用于 fb:like 按钮或登录脚本。

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
  FB.init({
    appId  : 'YOUR APP ID',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true  // parse XFBML
  });
</script>

关键是将 xfbml 设置为 true(这是 #xfbml=1 所做的)。如果您没有该设置,则不会呈现类似按钮。

如果您想订阅登录事件,只需在 FB.init() 调用之后添加以下脚本:

  FB.Event.subscribe('auth.login', function(response) {
    window.location.reload(); // or something else...
  });

只有当用户单击链接、按钮等时才会触发您的登录脚本。

function doLogin() {
   FB.login(function(response) {
     if (response.session) {
       if (response.perms) {
         // user is logged in and granted some permissions.
         // perms is a comma separated list of granted permissions
       } else {
         // user is logged in, but did not grant any permissions
       }
     } else {
       // user is not logged in
     }
   }, {perms:'read_stream,publish_stream,offline_access'});
}
于 2011-01-18T02:39:00.457 回答
0

将此 xmlns 添加到您的 html 标记

xmlns:fb="http://www.facebook.com/2008/fbml"

并包括“all.js”

于 2011-01-24T09:36:24.460 回答