【问题标题】:facebook share error: "method" is a required parameter for FB.ui()facebook 分享错误:“方法”是 FB.ui() 的必需参数
【发布时间】:2012-01-29 17:39:48
【问题描述】:

标题说明了一切。我总是得到这个错误: “方法”是 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>

【问题讨论】:

  • 这似乎是您的应用程序的问题,因为任何共享选项都不适用于您的 APP_ID(取自link 指定的站点)请确保您的应用程序配置正确且未被阻止。跨度>

标签: javascript facebook share


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    你确定这段代码是你错误的根源吗?

    【讨论】:

    • 是的,我也只是从教程中复制了这个例子......这是什么语法问题?您是在本地还是在实时服务器上对其进行了测试??
    【解决方案3】:
    • 你必须在服务器上在线(真正的服务器)
    • 如果您在此行中没有 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

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

    【讨论】:

    猜你喜欢
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 2017-07-10
    相关资源
    最近更新 更多