I have a site for shopping recommendations, which allows users to post the urls for items they recommend.
The form currently includes just a single input for a url to the main product page.
If a user were to post a link like below:
I would want to show an image tag of the og:image included in this url.
Using the facebook open graph protocol page, I see that the example url above does indeed have an og:image
How do I go about extracting the url to the og:image?
I ended up using Nokogiri like below, while relying heavy on this tutorial by Railscasts.
I found this to be more reliable than the opengraph gem:
as this second method sometimes doesn’t work, even on pages that have an og:image tag in the source code. (I didn’t implement it completely wrong, as it did work on some pages…).