title: Facebook share via FB.ui
body: <p>I am trying to use the following code that I wrote based on the new documentation for showing a "post to feed" dialog (<a href="https://developers.facebook.com/docs/javascript/reference/FB.ui" rel="noreferrer">https://developers.facebook.com/docs/javascript/reference/FB.ui</a>) but i get the following error "<strong>ReferenceError: FB is not defined</strong>"</p>
  
  <p>the code that i use is the simplest i can come up with:</p>
  
  <pre><code>window.fbAsyncInit = function() {     
      FB.init({
        appId      : 'xxxxxxxx',
        status     : true,
        xfbml      : true
      });
    };
  
    (function(d, s, id){
       var js, fjs = d.getElementsByTagName(s)[0];
       if (d.getElementById(id)) {return;}
       js = d.createElement(s); js.id = id;
       js.src = "http://connect.facebook.net/en_US/all.js";
       fjs.parentNode.insertBefore(js, fjs);
     }(document, 'script', 'facebook-jssdk'));
  
  
      FB.ui({
          method: 'feed',
          name: 'Facebook Dialogs',
          link: 'https://developers.facebook.com/docs/dialogs/',
          picture: 'http://fbrell.com/f8.jpg',
          caption: 'Reference Documentation',
          description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
      });
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>and if i want to open the dialog when a user clicks on a link i would use jquery click event</p>
  
  <pre><code>$(".userActions a.facebook").click(function() {
     FB.ui({
          method: 'feed',
          name: 'Facebook Dialogs',
          link: 'https://developers.facebook.com/docs/dialogs/',
          picture: 'http://fbrell.com/f8.jpg',
          caption: 'Reference Documentation',
          description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
      });
  });
  </code></pre>
  
  <p>or have the FB.ui inside a function that accepts parameters and call this function e.g.</p>
  
  <pre><code>window.fbAsyncInit = function() {     
      FB.init({
        appId      : 'xxxxxxxx',
        status     : true,
        xfbml      : true
      });
  
      // Code in here will run once FB has been initialised
  
      function FB_post_feed(method,name,link,picture,caption,description){
         FB.ui({
              method: method,
              name: name,
              link: link,
              picture: picture,
              caption: caption,
              description: description
          });
      }
  
  };
  
  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "http://connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
  </code></pre>
  
  <p>and somewhere in the HTML</p>
  
  <pre><code>$(".userActions a.facebook").click(function() {
      FB_post_feed('feed','Facebook Dialogs','https://developers.facebook.com/docs/dialogs/','http://fbrell.com/f8.jpg','Reference Documentation','Dialogs provide a simple, consistent interface for applications to interface with users.')
  }
  </code></pre>