please read through the whole post before marking this as duplicate of Facebook Share Story Image Does Not Appear For First time or related questions.
I'm creating a dynamic page (with unique url and image) that users can share on facebook with a share dialog.
According to https://developers.facebook.com/docs/sharing/best-practices#precaching Facebook need to scrape the url in og:image before it can show it in the share dialog.
This can be done either by using the sharing debugger OR setting og:image:width and og:image:height metatags on the page that is shared.
Since the site I'm making potentially can get a lot of unique pages and images, I don't want hack together a script to programmatic call the sharer debugger (or sharer.php with the unique urls) to make this work. So I'm trying to use the og:image:width and og:image:height metatags.
Unfortantly I've not been able to make this work.
The first time the page is shared it does not show the image specified in og:image. The second time it does.
I've created two demo-files to back this up:
http://beerco.de/fbgifshare/urls_without_ts.php This page has the follwing metatags and fb.ui code:
<meta property="og:url" content="http://beerco.de/fbgifshare/test.gif">
<meta property="og:title" content="Lorem Ipsum">
<meta property="og:description" content="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed fermentum lacinia nisl ut hendrerit. Sed elementum, urna id accumsan ultrices, lectus felis bibendum lectus, sed ornare velit elit eleifend ipsum.">
<meta property="og:image" content="http://beerco.de/fbgifshare/test.gif"
<meta property="og:image:width" content="500">
<meta property="og:image:height" content="500">
...
FB.ui({
method: 'share',
href: 'http://beerco.de/fbgifshare/urls_without_ts.php'
}, function(response){
console.log(response);
});
This will always work (after the initial share) since the href that is shared and the og:image is static.
http://beerco.de/fbgifshare/urls_with_ts.php This page will always share a unique URL and image:
<meta property="og:url" content="http://beerco.de/fbgifshare/test.gif?ts=1484855521">
<meta property="og:title" content="Lorem Ipsum">
<meta property="og:description" content="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed fermentum lacinia nisl ut hendrerit. Sed elementum, urna id accumsan ultrices, lectus felis bibendum lectus, sed ornare velit elit eleifend ipsum.">
<meta property="og:image" content="http://beerco.de/fbgifshare/test.gif?ts=1484855521">
<meta property="og:image:width" content="500">
<meta property="og:image:height" content="500">
...
FB.ui({
method: 'share',
href: 'http://beerco.de/fbgifshare/urls_with_ts.php?ts=1484855521'
}, function(response){
console.log(response);
});
The share dialog will not show the image preview the first time I open the feed dialog but it may show it if I try again (without reloading the page) because facebook then have scraped the image.
If i refresh the page and try to share again the preview is not shown since the urls got a new timestamp.
Am I missing something here or is the facebook documentation wrong?
I need the image preview to be shown the first time the user shares the page.
What is the best way to achieve this?
The reason for having the image-url in both og:image and og:url is because I want the animated gif to be played inline in facebook (like giphy does) when the page is shared.
Please view source on the two demo-files to see all OG tags and FB.ui code.
All help appreciated!