facebook共享错误:“method”是FB.ui()的必需参数

时间:2012-01-29 17:39:48

标签: javascript facebook share

标题说明了一切。我总是得到这个错误: “method”是FB.ui()的必需参数。但方法设置为'feed'

是因为我目前在我的机器上本地工作而不是真正的服务器吗? 应用程序也在Facebook注册。

有什么想法吗?

<span id='share'>SHARE</span>   
<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({appId: '2907534********', 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);
    }());
</script>
<script type="text/javascript">
    $(document).ready(function(){
            $('#share').click(function(e){
                e.preventDefault();
                FB.ui({
                    method: 'feed',
                    name: 'This is the content of the "name" field.',
                    link: ' http://www.hyperarts.com/',
                    picture: 'http://www.hyperarts.com/external-xfbml/share-image.gif',
                    caption: 'This is the content of the "caption" field.',
                    description: 'This is the content of the "description" field, below the caption.',
                    message: ''
                    });
                });
            });
</script>

3 个答案:

答案 0 :(得分:2)

代码的$('#share').click(function(e){部分应该进入window.fbAsynchInit调用,以确保在将click事件分配给使用FB的事件之前加载框架。

答案 1 :(得分:1)

我使用自己的应用ID测试了相同的代码,它对我来说很好。唯一的区别是我将名称,标题和描述更改为“This”,最后修复了语法问题。

您确定这段代码是错误的来源吗?

答案 2 :(得分:0)

  • 您必须在服务器(真正的服务器)上联机
  • 如果您在此行中没有Facebook ID     FB.init({appId:'2907534 ********',状态:true,cookie:true,xfbml:true});  您必须拥有此网址中的一个:https://developers.facebook.com/  或搜索如何创建Facebook应用程序  (如何创建Facebook应用程序的示例) hyperarts.com/blog/how-to-create-facebook-application-to-get-an-app-id-for-your-website /
  • 但是如果您已经拥有facebook id并且已经知道如何创建应用程序,则必须将代码放在顶部,放在Facebook画布上的同一文件中,

例如,如果您在画布中插入(https://www.example.com/test.php) 并且您必须将此代码放在test.php

我希望你的问题能尽快解决!