我正在使用Twitter Card Preview用于测试我的 Twitter 卡设置的工具。
<meta property="twitter:url" content="http://liberalgeek.com/content/why-do-atheists-celebrate-christmas" />
<meta property="twitter:card" content="summary" />
<meta property="twitter:description" content="I can't speak for all atheists, I can only speak for myself, so please leave a comment below and explain why you celebrate Christmas! When I hear someone ask, "Why do atheists celebrate Christmas?" my first thought often is: Better Question: Why do Christians celebrate Christmas?" />
<meta property="twitter:creator" content="@kennywyland" />
<meta property="twitter:title" content="Why do Atheists celebrate Christmas?" />
当我使用上述元标记时,预览可以正常工作,并且我得到了预期的结果。当我尝试添加 twitter:image 标签时,它失败了。这是一个例子:
<meta property="twitter:image" content="http://liberalgeek.com/sites/default/files/styles/large/public/Christmas%20Tree.jpg" />
如果我包含 twitter:image 元标记并单击“预览”按钮,它会旋转一会儿,然后给出错误:
Looks like something is technically wrong.
Please try again in a few minutes.
我尝试过该网站上的其他图像,但没有成功。我尝试过托管在同一 apache 服务器上的其他(非 drupal)站点,以确保这不是 drupal 问题:
<meta property="twitter:image" content="http://www.journalscape.com/kenny/images/acupuncture-kenny-2003-08-20-small.jpg" />
如果我将这些图像之一复制到具有不同 apache 服务器的另一台计算机,twitter 会看到它并且它工作得很好。 Twitter 在预览中显示了它。
我已经检查了两个网站上的 robots.txt。我的 robots.txt 中的任何内容都不应阻止 Twitterbot 获取,但以防万一我已明确添加了他们建议的代码:
User-agent: Twitterbot
Disallow:
但是,我看着我的 apache 网络日志滚动,而 Twitter 从未尝试获取图像。当我单击预览按钮时,我希望在访问日志中看到一个条目,显示 Twitter 正在获取图像......但什么也没有。我已经尝试了几张图像以确保这不是缓存问题。
我做错了什么?
编辑:我发现在我的机器上运行的网站之一(相同的 apache)工作得很好。如果我使用这张图片:
<meta property="twitter:image" content="http://www.geekqi.com/images/StylizedYinYangRedLucida.png" />
然后 Twitter 立即获取它。我不明白为什么一个有效而另一个无效。
最佳答案
事实证明,问题出在时间问题上。添加 robots.txt 文件后,我需要等待几个小时才能让 Twitter 看到新的 robots.txt,然后它开始正常获取我的图像。
关于html - Twitter 卡片预览无法获取我的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14131188/