Getting basic information from Instagram using PHP

In case you need to grab follower count (or other fields) without logging in, Instagram is nice enough to put them in JSON inside the page source:

$raw = file_get_contents('https://www.instagram.com/USERNAME'); //replace with user
preg_match('/\"edge_followed_by\"\:\s?\{\"count\"\:\s?([0-9]+)/',$raw,$m);
print intval($m[1]);

//returns "123"

Hope that helps.

24 May 2016 Updated to be more tolerant of spaces in JSON.

19 Apr 2018 Updated to use new “edge_” prefix.

Leave a Comment