FB.ui /发布流问题

时间:2011-01-20 18:45:00

标签: javascript facebook

我正在尝试使用FB.ui从我的客户网站发布一个简单的流到Facebook,但当我运行“streamPublish”方法时,我只是得到“发生错误。请稍后重试。”< / p>

我的代码如下: -

<head>
 <title>A Dynamic Comment System</title>
 <meta http-equiv="content-type" 
  content="text/html;charset=utf-8" />
 <meta http-equiv="Content-Style-Type" content="text/css" />

 <!-- Javascript Librairys -->
 <script src="http://connect.facebook.net/en_US/all.js"></script>
 <script type="text/javascript" src="javascripts/commentsystem.js"></script>

 <!-- Style Sheets -->
 <style type="text/css" media="all">
  @import "css/commentstyles.css";
 </style> 

  <script> 
           window.fbAsyncInit = function() { 
    FB.init({appId: "180166762023187", 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); 
   }());

   function streamPublish()
   {       
    FB.ui(  
      {   method: 'stream.publish',display:'popup', message: 'getting educated about Facebook Connect', 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://github.com/facebook/connect-js'     
       },  action_links: [{ text: 'Code', href: 'http://github.com/facebook/connect-js' }],     
        user_message_prompt: 'Share your thoughts about Connect'   
      },   
      function(response) 
      {     
       if (response && response.post_id) 
       {       
        alert('Post was published.');     
       } 
       else 
       {       
        alert('Post was not published.');     
       }   
      } );
   } 
   </script> 
</head>

我对FB API并不熟悉,所以我完全难过 - 任何帮助都非常感谢! :)

2 个答案:

答案 0 :(得分:1)

我有同样的问题,我把FB.init放在window.fbAsyncInit中,但是当我刷新页面时,它显示错误。我已经通过将FB.init放入调用onclick事件的javascript来解决它了

FB.init({appId: "12345", status: true, cookie: true, 
            xfbml: true}); 
FB.ui(
  {
method: 'feed',
name: 'WIN A TRIP TO NYC!',

希望它对您有用:)

答案 1 :(得分:0)

我读到如果在FB.init完成之前调用FB.ui会发生这种情况。我也遇到了问题,将FB.init放在我的onload函数中有帮助,但并没有完全解决问题。我希望这可以帮助你。