0

I'm setting my open graph tags dynamically.

Example:

<meta property="og:image" content="http://eminegri.altervista.org/canvas/<?php echo $_GET["img"];?>"/>

It works: Facebook debugger catches the image and when I share the link, the image appears successfully!

But I've one problem: in the share window, the image doesn't appear. It appears only if I open the share window 3/4 times.

Does anyone know how can I fix it?

Nadeem_MK
  • 7,533
  • 7
  • 50
  • 61
ene
  • 75
  • 1
  • 11
  • What you're doing is really dangerous - never do `echo $_GET['anything']`. Instead, use `htmlentities($_GET['img'])` to prevent XSS. (see this http://stackoverflow.com/q/15755323/3132718 and http://stackoverflow.com/q/5986972/3132718) – Al.G. Apr 19 '15 at 14:41
  • Ok, I've change it! Thank you Btw, anything about my initial question? – ene Apr 19 '15 at 15:09
  • I can't tell you anything just because I don't know :) I noticed your problem while reviewing questions but unfortunately I'm not competent in this topic. – Al.G. Apr 19 '15 at 15:14
  • No problem! Thank you for the htmlentities thing :) – ene Apr 19 '15 at 15:34

1 Answers1

0

Ok, I've found out how to fix it. You have to add the og:image:width and og:image:height to make Facebook able to render the image at the first share.

https://developers.facebook.com/docs/sharing/best-practices

I hope that someone will find this usefull :)

ene
  • 75
  • 1
  • 11