2010-08-31 25 views
1

我的FB.ui stream.share和stream.publish可以很好地工作,但當我調用回調函數時,即使故事發布在我的Facebook個人資料上,它總是返回錯誤。Facebook FB.ui stream.share錯誤

 [script] <div id="fb-root<?php the_ID();?>"></div> 
     <script> 
       window.fbAsyncInit = function() { 
       FB.init({appId: '151136734905815', 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<?php the_ID();?>').appendChild(e); 
     }()); 

     function fb_share (url, title){ 
     var share = { 
      method: 'stream.share', 
      display: 'dialog', 
      u: url, 
      t: title 
     }; 

     FB.ui(share, function(response) { 
      if (response && response.post_id) { 
      alert(response.post_id); 
      } else { 
      alert('Error: Post was not published due to some error. Please try again later.'); 
      } 

      }); 
     } 
     </script>[/script] 

它總是返回錯誤:由於某些錯誤,發佈未發佈。請稍後再試。即使故事已成功在Facebook中,也可以使用。對此有何幫助?

+0

您是否嘗試過輸出響應到螢幕控制檯?看看它包含什麼,可能是一些錯誤代碼。另外爲什麼你追加一些id到'fb-root'?你有多個FB實例或什麼? – serg 2010-09-01 22:08:48

+0

Hi Serg, 不,我沒有嘗試過。另外,我在wordpress中使用它,所以我認爲在index.php中,每個帖子都有自己的Facebook彈出窗口,爲什麼?這是必要的嗎? – 2010-09-02 06:26:58

+0

嗨Serg,我試過Firebug的console.log,它也顯示undefined。現在有什麼想法? – 2010-09-06 05:11:09

回答

1
$('#share').bind('click', function(e){ 
    var share = { 
     method: 'stream.share', 
     u: 'http://your/share/url/with/id/123' 
    }; 
    FB.ui(share, function(){ 
     $.post("/log_shares.php", {"id": 123}); 
    }); 
    e.preventDefault(); 
}); 
相關問題