繁体   English   中英

Facebook分享错误:“方法”是FB.ui()的必需参数

[英]facebook share error: “method” is a required parameter for FB.ui()

标题说明了一切。 我总是收到此错误:“方法”是FB.ui()的必需参数。 但是方法设置为“提要”

是因为我当前在计算机上本地工作,而不是在真正的服务器上工作? 应用也已在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>

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

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

您确定这部分代码是错误的根源吗?

  • 您必须在服务器(实际上是服务器)上在线
  • 如果此行中没有Facebook ID,则FB.init({appId:'2907534 ********',状态:true,cookie:true,xfbml:true}); 您必须从以下网址获得一个: https : //developers.facebook.com/或搜索如何创建Facebook应用程序(如何创建Facebook应用程序)hyperarts.com/blog/how-to-create-facebook-的示例应用程序为您的网站获取一个应用程序ID /
  • 但是,如果您已经有了facebook id并且已经知道如何创建应用程序,则必须将代码放在顶部(与放置在facebook画布上的文件相同),

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

希望您的问题能很快得到解决!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM