【问题标题】:Facebook custom share button not showing descriptionFacebook 自定义分享按钮不显示描述
【发布时间】:2014-03-05 02:26:29
【问题描述】:

我正在使用以下 JS 代码在 facebook 上分享。

function openFbPopUp() {
    var fburl = 'http://54.251.121.6/cnc/cupcakes-n-chai-side-table';
    var fbimgurl = 'http://imageURL';
    var fbtitle = 'Your title';
    var fbsummary = "This is the description blah blah blah";
    var sharerURL = "http://www.facebook.com/sharer/sharer.php?s=100&p[url]=" + encodeURI(fburl) + "&p[images][0]=" + encodeURI(fbimgurl) + "&p[title]=" + encodeURI(fbtitle) + "&p[summary]=" + encodeURI(fbsummary);
    window.open(
      sharerURL,
      'facebook-share-dialog', 
      'width=626,height=436'); 
    return  false;
}

在弹出窗口中,描述文本看起来不错。但是当在 facebook 上看到时,描述并没有显示出来

分享时,可以看到描述(摘要文字)

描述(摘要文本)未显示在 facebook 中。

【问题讨论】:

    标签: javascript facebook-opengraph facebook-sharer


    【解决方案1】:

    在您分享的任何页面上,尝试输入以下内容:

    <meta property="fb:app_id" content="{Your_App_ID}"/>
    <meta property="og:url" content="http://54.251.121.6/cnc/cupcakes-n-chai-side-table"/>
    <meta property="og:title" content="Your title"/>
    <meta property="og:image" content="http://imageURL"/>
    <meta property="og:description" content="This is the description blah blah blah">
    

    但是,如果您已经在使用 JS,那么使用 Facebook JS SDK 怎么样?

    只需将以下代码放在您的标签后面:

    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId      : '{your-app-id}',
          status     : true,
          xfbml      : true
        });
      };
    
      (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/all.js";
         fjs.parentNode.insertBefore(js, fjs);
       }(document, 'script', 'facebook-jssdk'));
    </script>
    

    然后,要调用共享对话框,只需调用以下代码:

    FB.ui({
            method: 'feed',
            name: 'Your title',
            link: 'http://54.251.121.6/cnc/cupcakes-n-chai-side-table',
            picture: 'http://imageURL',
            caption: '',
            description: 'This is the description blah blah blah',
            ref: '{your_reference_call_here}'
    });
    

    我的个人经验表明,使用 JS SDK 共享内容比使用 URL 重定向方法更安全(确保没有错误)。

    【讨论】:

    • 感谢@Aashish Tripathee。我不能使用元描述标签,因为有些页面需要在页面的不同块上使用 3-4 个不同的元描述标签。
    • 然后尝试使用JS SDK。这绝对有效,并且在您的情况下共享多个内容时非常好。:)
    猜你喜欢
    • 2016-03-19
    • 2014-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 1970-01-01
    • 2014-01-13
    • 1970-01-01
    相关资源
    最近更新 更多