简体   繁体   English

如何使Facebook从帖子中的URL缩略图图像

[英]How to get Facebook to thumbnail an image from URL in post

I'm building an image library site. 我正在建立图片库网站。 It will be mostly private but I'd like users to be able to directly use certain images in facebook posts by special URLs. 它主要是私人的,但是我希望用户能够通过特殊的URL直接使用Facebook帖子中的某些图像。

The URLs look plain enough: http://example.com/some/path/image.jpg although they're actually generated on demand by a script. 这些URL看起来很普通: http://example.com/some/path/image.jpg : http://example.com/some/path/image.jpg尽管它们实际上是由脚本按需生成的。

But when I paste that URL (the URL of the image, not a page with the image on) to Facebook it just comes up with the domain name; 但是,当我将该URL(图像的URL,而不是图像所在的页面)粘贴到Facebook时,它只是带有域名。 it does not thumbnail the image. 它不会缩略图图像。

There are many questions about open graph meta tags - but that's to do with pages, and this question is about the case of a post with a direct image URL. 关于开放图元标记有很多问题-但这与页面有关,而这个问题是关于带有直接图像URL的帖子的情况。 I notice that it works for images from imgur, for example. 我注意到它适用于来自imgur的图像。

Is there something in the way the image is served, or something about the quality of the image itself that I can change to get facebook to work? 提供图像的方式是否存在某些问题,或者我可以更改一些图像本身的质量以使Facebook工作? Or is it just something like facebook knows to treat certain image sites a different way? 还是像Facebook知道的那样以不同的方式对待某些图像网站?

Thanks. 谢谢。

I think Facebook grabs the image using some kind of OpenGraph "Browser". 我认为Facebook使用某种OpenGraph“浏览器”来捕获图像。 So you need to serve it meta information depending on the User-Agent, which is 因此,您需要根据用户代理为其提供元信息,即

facebookexternalhit/1.1 (+https://www.facebook.com/externalhit_uatext.php)

for Facebook. 对于Facebook。

So when a user browser hits your URL you serve the image, when it's facebook you serve it open-graph meta-data. 因此,当用户浏览器点击您的URL时,您将提供图片;当它是Facebook时,您将为其提供开放图元数据。

The only thing, off the top of my head, that I can think of is your favicon for that page. 我能想到的唯一的事情就是您在该页面上的收藏夹图标。

Visit http://www.w3.org/2005/10/howto-favicon for information on favicons in html. 请访问http://www.w3.org/2005/10/howto-favicon,以获取有关html中的图标图标的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM