-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Additional/alternate images not displayed in Facebook generated share previews #131
Comments
Looks like facebook is stripping the query string. Did you try encoding the URI? |
Yeah it would appear so. They seem to serve them through their own safe_image endpoint. I tried encodeURI on the generated image link, but that broke the additional image content and text, and additionally was still ignored by Facebook. Unless you mean to encode at a different point. |
What is safe_image? Perhaps they assume the query string is malicious and strip it? Or maybe it is too long? |
For example the Prismic image is served as <img class="scaledImageFitWidth img"
src="https://external-lht6-1.xx.fbcdn.net/safe_image.php?d=AQAj_z3s3CGmYiiP&w=540&h=282&url=https%3A%2F%2Fog-image.now.sh%2FNext.js%2520Blog%2520Example%2520with%2520%2A%2APrismic%2A%2A.png%3Ftheme%3Dlight%26md%3D1%26fontSize%3D75px%26images%3Dhttps%253A%252F%252Fassets.zeit.co%252Fimage%252Fupload%252Ffront%252Fassets%252Fdesign%252Fnextjs-black-logo.svg%26images%3Dhttps%253A%252F%252Fi.imgur.com%252FGVmKYul.png%26widths%3Dundefined%26widths%3Dauto%26heights%3Dundefined%26heights%3D100&cfs=1&upscale=1&fallback=news_d_placeholder_publisher&_nc_hash=AQCdMzQI9yj5Tu8o"
data-src="https://external-lht6-1.xx.fbcdn.net/safe_image.php?d=AQAj_z3s3CGmYiiP&w=540&h=282&url=https%3A%2F%2Fog-image.now.sh%2FNext.js%2520Blog%2520Example%2520with%2520%2A%2APrismic%2A%2A.png%3Ftheme%3Dlight%26md%3D1%26fontSize%3D75px%26images%3Dhttps%253A%252F%252Fassets.zeit.co%252Fimage%252Fupload%252Ffront%252Fassets%252Fdesign%252Fnextjs-black-logo.svg%26images%3Dhttps%253A%252F%252Fi.imgur.com%252FGVmKYul.png%26widths%3Dundefined%26widths%3Dauto%26heights%3Dundefined%26heights%3D100&cfs=1&upscale=1&fallback=news_d_placeholder_publisher&_nc_hash=AQCdMzQI9yj5Tu8o"
style="top:0px;" alt="" width="524" height="274" caption="">
I've tested toggling the color theme from light to dark and additionally the font size. These both work fine and are reflected in the FB share. As these are after the query string it shows it is not being entirely stripped. Probably they're considering the URLs for the images malicious? and removing those parameters. |
As an update, I have looked into it further, mostly just through trial and error. It appears that FB processing operates on two fronts.
This is just through my testing so may not be 100% accurate. A solution I have come up with to get all the image information through FB involves creating an object of the urls, heights and widths. This is then JSON stringified and added as the image parameter. The JSON stringification is seemingly non-obvious enough that FB does not detect the URLs and strip the parameter. As this also allows for all information in one parameter it does not run into the repeated parameter removal issue. Obviously this fix would be a breaking change going forwards, but it could be introduced as a new parameter which if present means the old images, widths and heights are ignored? Would be interested to hear if you have any ideas on how to resolve these restrictions? @styfle |
That might work, but a better solution for your use case is to fork this repo and make changes that suite your needs. Likely any major change is going to take a long time to review. |
Yep totally agree. If you're interested I have an implementation here spinks/og-image@45439b7. For me this works with Facebook, and allows for falling back to the current parameter structure. |
Thanks for investigating! I'll circle back here when I have more time and I'll leave this issue open in case someone runs into the same problem. Great work 🎉 |
Closing in favor of #226 |
When using more than one image (logo), Facebook does not appear to generate the correct image. The secondary images are not added.
Facebook also does not use the correct first image (logo), instead using the default. This issue does not seem to be present for other sites like Twitter.
I am not sure what could be causing it.
Below are some examples, taken from the Next.js documentation pages about CMSs. They illustrate how the first icon is incorrect, (Vercel as opposed to Next.js) and the secondary ones are not present.
The text was updated successfully, but these errors were encountered: