1

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

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

Sign up to request clarification or add additional context in comments.

8 Comments

Hi mrtom, thanks a ton for the answer. But the problem i am facing right now is when i copy the above page i.e telliott.net/facebookExamples/simpleAsyncInit.html on to ma desktop and open it, it throws an error some thing like ' Invalid arguement. An error occured with API tester. Please try again later.' What does this mean? And also, y do we have to specify href as fbrell.com/ or telliott.net/fb/... Whats the importance of these sites?
You have to post a link which directs to your applications connect or canvas URL - you can't choose an arbitrary URL. Which browser are you working with? Try Chrome - only because it's what I'm using here. There may be errors in my 'working' example, especially in IE, as I didn't test it extensively
I am using chrome. And here on your website when i click on the Button I get wat is required. Anyway, ma question is, did you use any server side scripting ( or any changes u made on the files in the server ) to get this one done. Why because, when i copy the web page and working offline if i click on the button.. It shows an error.
No, it's all front end only. There's nothing that you can't see in that page. Perhaps it's a problem with your application settings on Facebook?
Pretty much sure that its not the problem with the application settings. Because i didnt even change the app id specified by u. All it says is...'Invalid arguement'. Stuck with a seriously annoying problem...! Just press 'ctrl+s' and save the page somewhere in the system. Open it and click on the button only to see 'Invalid arguement. Error with APItester' :( :(
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.