2

We have a site that we want users to share an image based on the results of their input. Basically a map with selected countries unique to them.

We previously could do this using the sharer.php parameters up until about today but these now seem to have bitten the dust for good. They were due to be discontinued this month.

Our alternative (hopefully someone has better!) is to set the og:image property for our home page (which is what we want linked on the FB post) dynamically based on the URL parameter. All seems straight-forward, however whenever we test share FB uses the standard image for the home page as if there is no URL parameter.

Does anyone know definitively if FB uses the URL parameters when it crawls a site to get the image? Our tests seems to show they don't but if anyone knows a way around this I would be eternally grateful.

FYI, here are the og tags so you can see how they're set dynamically. It's web2py but should make sense I hope:

<meta property="og:url" content="{{=cfg.global_base_url + request.env.web2py_original_uri}}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="{{=(cfg.global_strap_line +  ' | ' + cfg.global_app_name) if not response.title else response.title}}" />
<meta property="og:description" content="{{=cfg.global_open_graph_description if not response.description else response.description}}" />
<meta property="og:image" content="{{=cfg.global_share_image if not response.share_image else response.share_image}}" />
<meta property="og:locale" content="en_GB" />

Here's an example share URL: https://www.wherecani.live?pid=9d684d33-78ad-4f39-9010-458583dbfcef

You can see in the HTML that the og:image relates to the URL parameter as expected.

Ian Ryder
  • 21
  • 1
  • 3
  • 2
    Yes, they'll respect URL parameters. After all, they can't tell the difference between `article=123` and `tracking_code=123`. Those URL parameters will need to be in the `og:url` output, though, as `og:url` is the "canonical" URL Facebook will do the fetching from. – ceejayoz Jul 20 '17 at 15:08
  • You need to set `og:url` to the respective URL including the parameter for this to work. But be aware that this will split the like and share count between those different URLs as well. – CBroe Jul 20 '17 at 15:12
  • Thanks for replies - looks like it's working OK now - in the early tests I hadn't changed the og:url but even after the change it didn't seem to be working. I may have not given it enough chances after the earlier failures – Ian Ryder Jul 21 '17 at 11:58

1 Answers1

0

I had the same problem. This is how i fixed it.

This is going to show the default imageL

<meta property="og:url" content="http:example.com">
<meta property="og:image" content="http:example.com/img/fb.jpg">

To change the image dynamically based in the url, you need to also add the og:url like this

<meta property="og:url" content="http:example.com/pages/cars">
<meta property="og:image" content="http:example.com/img/pages/cars/fb.jpg">

It worked for me. Tested in open graph.

Here's another explanation.

ETO
  • 6,970
  • 1
  • 20
  • 37
Rolly
  • 3,205
  • 3
  • 26
  • 35