How to check if the Instagram image has been deleted

advertisements

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 "https://instagram.com/p/#{shortcode}"

And if you access for example legit url with (Ruby): open "https://instagram.com/p/1" 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.

begin
      link = "https://instagram.com/p/#{submission.image}"
      submission.visible = true
      open link, :allow_redirections => :all
rescue OpenURI::HTTPError => e
      if e.message.include? '404 NOT FOUND'
        submission.visible = false
      end
end

Do you have any ideas?


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

https://instagram.com/developer/endpoints/media/#get_media