facebook-javascript-sdk – Facebook调试工具显示正确的标签,sharebutton生成不同的结果

我已经设置了我的og标签. Facebook调试工具显示正确的标签并生成正确的共享预览.但是,我网站上的共享按钮会产生不同的结果.它添加了带标题的h2标头标签,没有摘要.

我的代码:

<meta property="og:title" content="Page-Title"/> 
<meta property="og:url" content="Page-URL"/> 
<meta property="og:image" content="Page-Image"/>
<meta property="og:description" content="Page-Description" />

初始化Facebook分享按钮

window.fbAsyncInit = function() {
  FB.init({
    xfbml      : true,
    version    : 'v2.5'   
  });
};
(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/sdk.js";
   fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

最佳答案 看起来你缺少类型元属性和按钮本身的html.

它应该是:

<html>
<head>
    <title>Your Website Title</title>
    <!-- You can use Open Graph tags to customize link previews.
    Learn more: https://developers.facebook.com/docs/sharing/webmasters -->
    <meta property="og:url"           content="http://www.your-domain.com/your-page.html" />
    <meta property="og:type"          content="website" />
    <meta property="og:title"         content="Your Website Title" />
    <meta property="og:description"   content="Your description" />
    <meta property="og:image"         content="http://www.your-domain.com/path/image.jpg" />
</head>
<body>

    <!-- Load Facebook SDK for JavaScript -->
    <div id="fb-root"></div>
    <script>(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/sdk.js#xfbml=1";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>

    <!-- Your share button code -->
    <div class="fb-share-button" 
        data-href="http://www.your-domain.com/your-page.html" 
        data-layout="button_count">
    </div>

</body>
</html>
点赞