简体   繁体   中英

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.

The URLs look plain enough: http://example.com/some/path/image.jpg although they're actually generated on demand by a script.

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; 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. I notice that it works for images from imgur, for example.

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? Or is it just something like facebook knows to treat certain image sites a different way?

Thanks.

I think Facebook grabs the image using some kind of OpenGraph "Browser". 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.

So when a user browser hits your URL you serve the image, when it's facebook you serve it open-graph meta-data.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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