artfulrobot
artfulrobot

Reputation: 21397

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.

Upvotes: 0

Views: 309

Answers (2)

Dominik P
Dominik P

Reputation: 117

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.

Upvotes: 1

Henry Pye
Henry Pye

Reputation: 37

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.

Upvotes: 0

Related Questions