【问题标题】:Share link to posts when using FB.ui使用 FB.ui 时分享帖子链接
【发布时间】:2015-10-08 16:25:49
【问题描述】:

我为 FB 制作了一个小应用程序,它使用 FB.ui 允许用户在他们的墙上分享它。我希望分享的帖子在“评论”和“喜欢”旁边显示“分享”链接,就像在任何普通的墙贴上一样。

有没有办法用 FB.ui 做到这一点?

或者还有其他方法可以让我为墙贴定义自定义图像、标题、描述等吗?

我当前的代码:

function share(name, description) {
        FB.ui({
            method: 'feed',
            name: name,
            picture: '/img/fb.png',
            link: url,
            caption: '',
            message: '',
            description: description
            }, function() {
            });
    }

【问题讨论】:

    标签: facebook facebook-javascript-sdk facebook-wall fb.ui


    【解决方案1】:

    可以使用share_open_graph 方法完成。代码应该是这样的

    FB.ui({
        method: 'share_open_graph',
        action_type: 'og.shares',
        action_properties: JSON.stringify({
            object : {
               'og:url': 'http://astahdziq.in/', // your url to share
               'og:title': 'Here my custom title',
               'og:description': 'here custom description',
               'og:image': 'http://example.com/link/to/your/image.jpg'
            }
        })
        },
        // callback
        function(response) {
        if (response && !response.error_message) {
            // then get post content
            alert('successfully posted. Status id : '+response.post_id);
        } else {
            alert('Something went error.');
        }
    });
    

    【讨论】:

    • 我相信在提出这个问题之后已经添加了这个方法,但这看起来就像我当时正在寻找的东西。谢谢。
    • 我很高兴这能帮助到别人,:)
    【解决方案2】:

    对于the share action

    FB.ui({
      method: 'share',
      href: 'https://developers.facebook.com/docs/',
    }, function(response){});
    

    要定义自定义图像、标题、描述,请在页面头部使用Open Graph Tags

    <meta property="og:url" content="http://samples.ogp.me/136756249803614" /> 
    <meta property="og:title" content="Chocolate Pecan Pie" />
    <meta property="og:description" content="This pie is delicious!" /> 
    <meta property="og:image" content="https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/851565_496755187057665_544240989_n.jpg" />
    

    效果是:

    【讨论】:

      【解决方案3】:

      您必须使用 action 属性 参见文档here

      【讨论】:

      • 谢谢,但您能否更具体一点,您如何使用 action 属性来启用共享链接?该文档没有提及任何有关共享链接的内容。
      • action: [ { text: 'Game', href: 'example.com' } ],
      • 这只会创建一个名为“Game”的链接,该链接会转到“example.com”。我想做的是创建一个共享链接,允许用户在他们自己的墙上分享帖子,就像在正常状态更新上一样。
      • 嗯,也许你应该使用昨天发布的这个新功能developers.facebook.com/blog/post/2012/05/02/…
      猜你喜欢
      • 2014-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-09
      相关资源
      最近更新 更多