Instagram media by account in JSON

July 8th, 2017

Scraping inline JSON for fun and frustration

This will work until Instagram go ahead and make changes to their JS objects. Until then, go crazy.

So... within the Instagram page source is a SCRIPT tag that contains pretty much everything (almost) that you'd need to make a feed of your most recent Instagram posts. Its all within inline JS that isn't terribly awkward to parse out.

With that in mind, this is a quick demo to pull images with a comma-delimited list of Instagram usernames.

The PHP code is here: https://github.com/donohoe/code-examples/blob/master/instagram/get.php

Just follow the steps in the README.md to setup a local debug server and then you can run this in your browser:

http://localhost:7020/instagram/get.php?ids=nytimes,qz

Again, disclaimers about making sure you add better error reporting and if Instagram/Facebook change their code then this will need patching.