Search code examples
phpapiinstagramposts

Get Instagram posts count for profile


I'm using PHP to build an application that gets some statistics from individual Instagram accounts. I do a get request to the following URL to get a JSON formatted string:

https://www.instagram.com/{username}/?__a=1

With json_decode, I get the followers and the followings by:

$follows = $data['user']['follows']['count'];
$followedBy = $data['user']['followed_by']['count'];

But I don't know how to get the posts count.

For example for NASA profile: https://www.instagram.com/nasa/

... I need the number (currently) 1.967.

Any idea?

And a final question: do I have to use API Key to get the stats, or the GET to the above URL is enough?


Solution

  • what is wrong with

    $json = file_get_contents('https://www.instagram.com/nasa/?__a=1');
    $obj = json_decode($json);
    echo $obj->user->media->count;
    

    it just spit out the correct post count as you wanted?