Fetch Instagram Data with PHP

For the last couple of years I've maintained a PHP package to interact with the Instagram API. As of June 29, 2020, the Instagram platform will be deprecating its API. I've decided to archive the package as well. It is still possible to fetch data from Instagram and in this post I'll show you how.

To make HTTP requests, we're going to use the file_get_contents function. Replace the placeholder with a real username.

$response = file_get_contents('https://instagram.com/USERNAME/?__a=1');

Once we've fetched the JSON, lets convert it into something we can work with using the json_decode function.

$user = json_decode($response);

Now we've fetched the user's public Instagram data along with a couple of posts.

echo $user->graphql->user->full_name;

If you want to fetch all posts by a user, I suggest you take a look at Pierre Grimaud's Instagram package which is available on GitHub.