Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

When I first wrote about ingegreating with Facebook I shared an example on how to share a post link and provide additional data like a picture to use as a thumbnail. This used to tell Facebook that the provided picture should be shown as the link preview, this no longer works. You can still submit the 'picture' property as a URL but it will be ignored. This behaviour is described in the Graph API version 2.10. Fortunately there is a way to control which image Facebook will use.
fb_og_inferred2.png


First lets understand why this change has been made. Facebook had this to say about the topic.
As part of our continuing efforts to stop the spread of misinformation and false news on our platform, earlier this year at F8 we announced an important change to our Graph API: Graph API version 2.9 includes a 90 day deprecation of the ability to edit previews attached to link posts.


So it's all about fake news. Although I understand Facebook's position on this, I do not agree completely with this change. Lets look at what you can do now to control which image appears as a link preview thumbnail...



As Facebook said, the Open Graph meta tags are the currently supported way to modify link previews. Fortunately this is easy to add to a CMS or Blog system. It only took me a couple of hours to have a full end-to-end solution in my Blog's code working.

The trick is to implement tags like this in the <header> of your generated HTML page...
 OpenGraph image tags
<meta property="og:image" content="https://www.mydomain/myimage.jpg" />
<meta property="og:image:type" content="image/jpeg" />
<meta property="og:image:width" content="300" />
<meta property="og:image:height" content="300" />


The og:image tag is the one that is required, others are optional but I would recommend using them. This works the same way as back when the 'picture' property was supported with the API. Simply put the URL of the image into the content attribute and you're done. The image here needs to meet some guidelines e.g. it has be be less than 8Mb in size for Facebook to download it.

The og:image:type tag specifies the MIME type of the image. The og:image:width and og:image:height provide the width and height of the image (in pixels) respectively.

A PHP example on posting links is covered in Facebook's documentation here. Don't forget to use the URL Debugger after making your changes to ensure Facebook is behaving as you were expecting.

-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.