【问题标题】:Block certain images from Facebook js sharer阻止来自 Facebook js 共享器的某些图像
【发布时间】:2013-10-25 19:32:42
【问题描述】:

嗯,如标题所述,有什么方法可以阻止 Facebook js 共享器中的某些图像?

Facebook js 共享器会自动从页面中获取图像,并允许用户选择要在共享帖子中显示为缩略图的图像。目前,我们遇到了一种情况,它在页面上获取广告图像,而没有显示其他图像。

我可以想象横幅可以显示为 div 的背景图像,或者通过动态添加它们,但仍然可能存在用于排除图像的特殊标签或共享器初始化选项...在FB 文档,但它们非常“具体”...

为了澄清上述内容,请查看标记:

<!DOCTYPE html>
<html lang="en" 
      xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:og="http://ogp.me/ns#"
      xmlns:fb="https://www.facebook.com/2008/fbml">
 <head>
  <meta property="og:image" content="/logo.jpg">
 </head>
 <body>
  <article>
   ..plain text content
  </article>
  <aside>
   <img src="/banner.jpg"> <!-- fetched image for share, wrong -->
  </aside>
 </body>
</html>

P.S.:我读过这个问题:how to exclude an image from facebook sharer - 但实际上动态添加横幅(选择的答案)并不是它的本意。

【问题讨论】:

    标签: html facebook facebook-sharer


    【解决方案1】:

    这是我给a different questionanother answer 的C&P,虽然它也适合这里:

    您的问题的解决方案可能是检查真实用户或 Facebook 机器人是否正在访问您的页面。如果是机器人,则只为它渲染必要的元数据。您可以通过其用户代理检测机器人,根据Facebook documentation 是:
    "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"

    代码看起来像这样(在 PHP 中):

    function userAgentIsFacebookBot() {
        if ($_SERVER['HTTP_USER_AGENT'] == "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)") {
            return true;
        }
        return false;
    }
    

    【讨论】:

    • 标记为收藏,因为没有提供其他答案。但实际上,想得到更多的想法..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-17
    • 2016-10-12
    • 2015-02-05
    • 1970-01-01
    • 1970-01-01
    • 2014-12-05
    • 1970-01-01
    相关资源
    最近更新 更多