2015-12-11 24 views
0

我的代码看起来像这样Facebook API FB.ui提要报告错误 - 我该如何解决?

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></Script> 
<script type="text/javascript"> 
    FB.ui(
    { 
     method: 'feed', 
     name: 'Facebook Dialogs', 
     link: 'http://www.dynacal.com/default.aspx?OrgID=407&PageType=EDetail&EDID=1973', 
     picture: 'http://www.dynacal.com/File/GetFile.aspx?Logo=5942', 
     caption: '6:30AM - 07:45AM', 
     description: 'Boys 7th Grade Basketball Practice', 
     message: 'Facebook Dialogs are easy!' 
    }, 
    function (response) { 
     if (response && response.post_id) { 
      alert('Post was published.'); 
     } else { 
      alert('Post was not published.'); 
     } 
    } 
); 
</Script> 

这是结果。 发生错误。请稍后再试。

谁能告诉我我做错了什么?

回答

0

你没有在任何地方指定你的App ID,这很可能是错误的主要原因。更好地使用JavaScript的异步版本无论如何,例如:

window.fbAsyncInit = function() { 
    //SDK loaded, initialize it 
    FB.init({ 
     appId  : 'your-app-id', 
     xfbml  : true, 
     version : 'v2.5' 
    }); 

    //important! only after FB.init you can use FB.ui and stuff 
}; 

//load the JavaScript SDK 
(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 = "//connect.facebook.net/en_US/sdk.js"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk')); 

源(及更多信息):http://www.devils-heaven.com/facebook-javascript-sdk-login/

此外,您还需要调用用户交互FB.ui(鼠标点击),而不是页面加载。否则它会在某些浏览器中被阻止。并且没有message参数。