Instagram API Media Recent Call

Here I am going to show you how to connect to Instagram’s API using their “recent” call on media. At first this was very tricky to understand because their documentation lacks quite some important information, but after some digging, figured it out. So first off you need to be logged in to use an API call and have some sort of authentication to get it running. Of course there is the “terms of use” just like everything these days that could possibly keep you from being able to proceed with using the API, but that you’ll have to look into on your own, for now, we’re solely interested in actually using it.

Oh yeah, almost forgot, don’t user the name “Instagram” in your project, part of the rules…

Ok lets get started.
1) You need your userId & access_token. To get your access token follow the directions here: Instagram developer authentication and then you can get your userId from here:[username]&access_token=[access_token]

2) Once you have successfully achieved this, we can now start coding.

$userid = "12345";
$accessToken = "67890.12345";
$maxId = $_GET['max_id']; // this would be used for pagination if you want.
// Pulls and parses data.
$json_string = file_get_contents("{$userid}/media/recent/?access_token={$accessToken}&max_id={$maxId}");
$result = json_decode($json_string);

3) Now that its all good and we’re off and running, you’ll just need to make simple loops for your desired application. I would suggest using “print_r($result);” to get the consents from the requested method and do what you want from there.

Hope that helped.