Facebook在第一次分享时没有显示缩略图


Facebook don't show thumbnail image when share in the first time

在这个论坛尝试了很多方法,但它只工作80% .意思是当我点击分享按钮时,它工作正常,但有时它仍然无法获得缩略图当我分享一个帖子

尝试在第一页设置og:image,但仍然不工作。Mycode:

<meta property="og:image" content="http://www.example.com/a.jpg">
<meta property="og:image:secure_url" content="http://www.example.com/a.jpg">
<meta property="og:image:width" content="640">
<meta property="og:image:height" content="442">

有办法解决吗?感谢阅读

将此添加到header部分并更改您的应用程序id和Image的宽度和高度应与og:image:width and og:image:height相同

<meta property="fb:app_id" content=" your facebookAppId  " />
<meta property="og:title" content=" This is title of post " />
<meta property="og:url" content="http://www.example.com/a.jpg">
<meta property="og:image" content="http://www.example.com/a.jpg" />
<meta property="og:image:width" content="640" />
<meta property="og:image:height" content="442" />
<meta property="og:description" content=" This is description of post" />

和这些代码也可以帮助你

<div id="fb-root"></div>
                        <script src="https://connect.facebook.net/en_US/all.js"></script>

     <script>
/********* Code for deleting facebook cache ************/
                                FB.api(
                                        '/',
                                        'POST',
                                        {"scrape": "true", "id": "http://www.example.com/a.jpg"}, 
                                        function (response) {
                                        }
                                );
/********* Code for deleting facebook cache ************/
                            (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&version=v2.7&appId=xxxxxxxxxxfacebookAppId";
                                fjs.parentNode.insertBefore(js, fjs);
                            }(document, 'script', 'facebook-jssdk'));</script>
                          <div class="fb-share-button" data-href="http://www.example.com/a.jpg" data-layout="button"></div>

可能不是OG协议的问题。

即使你的代码是正确的,facebook scraper有时无法获得您的共享图像

有两种方法可以解决这个问题。

  1. 尝试使用facebook调试器让爬虫正确获取您的图像。https://developers.facebook.com/tools/debug/

  2. 修改共享图片的文件名。据我所知,Facebook将共享图片的缓存与图片的url一起保存了一天。所以如果你改变图片的url,让爬虫重新抓取你的url。