How to check if the Instagram image has been deleted


I've been trying to detect if Instagram image has been removed to hide those photos in my DB.

Right now I'm storing Instagram image short codes. And accessing images with "{shortcode}"

And if you access for example legit url with (Ruby): open "" then it returns 200 OK, on the other hand random not existing page throws exception 404.

But sometimes it seems to throw 404 on legitimate page, thats why my code does things which it shouldn't do on them.

      link = "{submission.image}"
      submission.visible = true
      open link, :allow_redirections => :all
rescue OpenURI::HTTPError => e
      if e.message.include? '404 NOT FOUND'
        submission.visible = false

Do you have any ideas?

You might need to use the API. Please check the media endpoints of Instagram's API if it helps: