Why FB.ui does not work even after loading javascript sdk?

风流意气都作罢 提交于 2019-12-09 23:31:39

问题


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> 

回答1:


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



来源:https://stackoverflow.com/questions/6894892/why-fb-ui-does-not-work-even-after-loading-javascript-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!