【问题标题】:Facebook sharer, thumb is showed instead of large imageFacebook 分享者,显示拇指而不是大图
【发布时间】:2017-02-03 15:40:09
【问题描述】:

我已经设置了一个比赛,要求参赛者在 facebook 上分享他们的结果。

我有以下按钮来分享结果:

print('<a class="facebook stemspeler" style="color:#eec920; margin-right:15px;" target="_blank" onclick="return !window.open(this.href, \'Facebook\', \'width=1200,height=300\')" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.***.com%2Fallstars&picture=http%3A%2F%2Fwww.***.com%2Ftypo.php?id='.$makeUniq.'&title=tet&caption=test&quote=test&description=test">‌​Share</a>');

$makeUniq 确保 facebook 获取结果而不是第一次缓存结果(当链接保持不变时它会缓存,现在不会因为链接更改每个请求)。

typo.php 是包含图像的文件。它采用标准模板并将比赛输入转换为图像叠加层。

<?php
session_start();
header("Cache-Control: no-store, no-cache, must-revalidate,    max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);

header("Pragma: no-cache");

// Output to browser
header('Content-Type: image/png');

// Create a 300x150 image

//WHITE BACKGROUND COLOR
$im = imagecreatetruecolor(1000, 1000);

$im = imagecreatefrompng("images/test.png");

$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$test = imagecolorallocate($im, 255, 255, 0);

// Set the background to be white
imagefilledrectangle($im, 0, 0, 900, 990, $test);

// Path to our font file
$font       = 'fonts/DINPro-Medium.ttf';
$fontSize   = 24;
$angle      = 0;

$x = 80;
$y = 150;
// Write it
imagettftext($im, $fontSize, $angle, $x, $y, $white, $font, ' : n');

$x = 80;
$y = 200;
// Write it
imagettftext($im, $fontSize, $angle, $x, $y, $white, $font, 'k : ');


$x = 80;
$y = 250;
// Write it
imagettftext($im, $fontSize, $angle, $x, $y, $white, $font, 'Ler :n');


$x = 80;
$y = 300;
// Write it
imagettftext($im, $fontSize, $angle, $x, $y, $white, $font, 'Mouwer : ');

$x = 80;
$y = 350;
// Write it
imagettftext($im, $fontSize, $angle, $x, $y, $white, $font, 'Rwer n');

$x = 80;
$y = 400;
// Write it
imagettftext($im, $fontSize, $angle, $x, $y, $white, $font, 'Rechtk : ');

$x = 80;
$y = 450;
// Write it
imagettftext($im, $fontSize, $angle, $x, $y, $white, $font, 'Cir : ');
imagepng($im);
imagedestroy($im);

?>

到目前为止,一切都按预期进行。

问题是当 facebook 分享功能打开时,facebook 一直将图像显示为缩略图而不是大图像。

我的目标是大图:

我尝试过多次更改分辨率,网上有几篇贴近描述这个问题的帖子。 有人知道我该如何解决这个问题吗?

提前致谢!

【问题讨论】:

    标签: php facebook facebook-sharer


    【解决方案1】:

    您可以尝试指定这些 OG 元素:

    og:image:width 
    og:image:height
    

    这些标签可帮助爬虫在下载之前获取您的图像大小。也许你得到一个更小的图像预览,因为爬虫一开始没有得到正确的大小,现在你从缓存中得到预览。

    编辑: 当然,您应该确保您使用的图像至少为 1200 x 630 像素

    【讨论】:

      【解决方案2】:

      Facebook 上共享链接的推荐图片尺寸为 1200x630。如果图片太小,Facebook 会居中裁剪并仅显示图片的缩略图。我相信最小尺寸是 600x315,但在高分辨率设备上结果可能不是很好。如果您希望它看起来不错并在所有设备上显示完整尺寸的图片,请使用 1200x630 像素的图片。

      您可以找到这些最佳做法的参考资料 here.

      编辑:

      您的问题可能是由于 Facebook 爬虫缓存了它所爬取的信息,因此即使您修复了旧图片的分辨率,FB 仍可能使用您的旧图片。确保转到here,以强制 Facebook 爬虫重新抓取您的网站并获取新数据,或者只是清空特定 URL 的缓存以强制它在您下次共享链接时重新抓取您的网站。否则 FB 可能仍然使用它已经在缓存中的旧图片。

      【讨论】:

      • 我尝试使用这些尺寸,但得到相同的结果。是否可以在 url 中发送高度和宽度作为参数?
      • @FrankW。我在上面编辑了我的答案。 - 可能是缓存问题。
      • Alberto 提到的 og:image:heigth 和 go:image:width 元标记仅在爬虫第一次爬取缓存中没有任何内容的 URL 时使用。如果您不包含它们,您将不会第一次在 Facebook 共享对话框中看到图像预览,因为它必须异步加载。如果包含它们,您将能够在共享对话框中看到图像预览,即使爬虫在缓存中没有任何内容,因为它能够同步加载它。在 Facebook 爬虫缓存所有内容之后,这些标签不再有用,所以这不是导致您的问题的原因。
      • 您好,感谢您的回答。问题是我没有在页面上发送元数据,但我将它们作为参数包含在我的 url 中。我必须这样做的原因是因为我不希望 facebook 缓存图像(参与内容的每个人都有不同的结果)。即使使用 url 中的参数,它也会缓存内容。通过使用 md5(rand()) 设法解决这个问题,因此每个字符串都是唯一的。所以说到重点,我确定它不会缓存图像,每次我点击分享按钮时,图像顶部的数据都是独一无二的,应该是。
      猜你喜欢
      • 2015-02-06
      • 1970-01-01
      • 2011-09-01
      • 2014-06-14
      • 2014-11-09
      • 2015-04-26
      • 2013-02-16
      • 1970-01-01
      • 2012-03-21
      相关资源
      最近更新 更多