为什么FB.ui不加载JavaScript SDK后甚至工作? [英] Why FB.ui does not work even after loading javascript sdk?

查看:160
本文介绍了为什么FB.ui不加载JavaScript SDK后甚至工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在浪费时间从为期一周试图找出什么不顺心这种特殊SIMPLE code样本。 Firefox的错误控制台说:没有定义FB.ui。我试图通过将code加载无微不至的JavaScript SDK来解决这个问题。但是,世界上没有影响。而所有的火狐说的是'FB.ui没有定义。有人帮我请。谢谢。 (注:我已经更换了XXX ......与马APPID)

 < HTML和GT;
    < HEAD>
    <标题>我的大网站与LT; /标题>
    < /头>
    <身体GT;
    < D​​IV ID =FB-根>< / DIV>    <脚本>  VAR发布= {方法:stream.publish,显示:'弹出',//弹出力模式
  附件: {
    名称:'连接',
    标题:Facebook的群JavaScript SDK,
    说明:(
      一个小的JavaScript库,可以让您利用+
      Facebook的的力量,带给用户\\'的身份,'+
      社交图和配电到您的网站。
    )
    HREF:http://fbrell.com/
  }
};
功能publish1()
{警报('2345');
    FB.ui(出​​版,Log.info.bind('stream.publish回调'));
    警报('自卫队');
}
< / SCRIPT><按钮的onclick =publish1()>点击< /按钮>< /身体GT;<脚本>    window.fbAsyncInit =功能(){
    FB.init({APPID:XXXXXXXXXXXXXXX',状态:真的,饼干:真实,
             XFBML:真});
  };
  (函数(){
    变种E =使用document.createElement('脚本'); e.async = TRUE;
    e.src = document.location.protocol +
      //connect.facebook.net/en_US/all.js';
    的document.getElementById('FB-根')的appendChild(E)。
  }());
< / SCRIPT>
< / HTML>


解决方案

有什么不对您的code本身。

运行外fbrell有没有日志对象,因此将无法在FB.ui线,但故障无关的FB.ui通话。

在fbrell它似乎失败,因为它找不到按钮的范围publish1功能运行。

下面是本质的code的考验,带着几分整理的空白,并清除日志行的。它可以成功发布到我的墙:

http://telliott.net/facebookExamples/simpleAsyncInit.html

I am just wasting time from last one week trying to figure out what goes wrong in this particular SIMPLE code sample. Firefox's Error Console says 'FB.ui not defined'. I tried to fix this by placing the code that loads javascript sdk in every possible way. But theres no effect. And all the firefox says is 'FB.ui not defined'. Someone help me out please. Thanks. (Note: I ve replaced the XXX... with ma APPID)

<html>
    <head>
    <title>My Great Website</title>
    </head>
    <body>
    <div id="fb-root"></div>

    <script>

  var publish = {method: 'stream.publish',display: 'popup', // force popup mode
  attachment: {
    name: 'Connect',
    caption: 'The Facebook Connect JavaScript SDK',
    description: (
      'A small JavaScript library that allows you to harness ' +
      'the power of Facebook, bringing the user\'s identity, ' +
      'social graph and distribution power to your site.'
    ),
    href: 'http://fbrell.com/'
  }
};


function publish1()
{alert('2345');
    FB.ui(publish, Log.info.bind('stream.publish callback'));
    alert('asdf');
}
</script>

<button onclick="publish1()">Click</button>

</body>

<script>

    window.fbAsyncInit = function() {
    FB.init({appId: 'XXXXXXXXXXXXXXX', status: true, cookie: true,
             xfbml: true});
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());


</script>
</html> 

解决方案

There's nothing wrong with your code per se.

Running outside of fbrell there is no Log object, so it will fail on the FB.ui line, but the failure has nothing to do with the FB.ui call.

Running within fbrell it seems to fail because it can't find the publish1 function in the scope of the button.

Here's a test of essentially your code, with a bit of tidying up of whitespace and the removal of the Log line. It can successfully post to my wall:

http://telliott.net/facebookExamples/simpleAsyncInit.html

这篇关于为什么FB.ui不加载JavaScript SDK后甚至工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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