Facebook API FB.ui提要报告错误 - 我该如何解决?

时间:2015-12-11 21:49:27

标签: javascript facebook feed

我的代码看起来像这样

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

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

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

1 个答案:

答案 0 :(得分: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。否则它会在某些浏览器中被阻止。并且没有<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="popupMenuStyle">@style/PopupMenu.Example</item> </style> <style name="PopupMenu.Example" parent="@style/Widget.AppCompat.Light.PopupMenu"> <item name="android:popupBackground">@drawable/menu_dropdown_panel_background</item> </style> 参数。