Instagram API: Fetch user’s followers and media

04 / Apr / 2014 by Komal Jain 1 comments

In my previous blog we learnt how to integrate Instagram login functionality in a Grails web app. Now we will see how to get Instagram user’s followers and media.

Once a user is logged in via the Instagram login API, we get a JSON response containing the logged in user’s profile information in JSON Format. A sample JSON is as follows:

[code]<br />
JSONObject userInfo = [<br />
user:[<br />
id:212545455,<br />
profile_picture:http://images.ak.instagram.com/profiles/profile_120652151_75sq_545454125.jpg,<br />
username:abcdefg45,<br />
bio:,<br />
website:,<br />
full_name:abcd xyz<br />
],<br />
access_token:122545212145.ddjsjdaa.002jdjwsdjdjdjndf7458<br />
]</p>
<p>String instagramUserId = userInfo.user.id<br />
String accessToken = userInfo.access_token<br />
[/code]

Now using this information, we can get the followers of the Instagram user as follows:

[code]<br />
String instagramFollowersUrl = &quot;https://api.instagram.com/v1/users/&quot; + instagramUserId + &quot;/?access_token=&quot; + accessToken<br />
URL url = new URL(queryString)<br />
return url.text<br />
[/code]

Too get all recent media posted by an Instagram user, the API call made is as follows:

[code]</p>
<p>String clientId = &quot;nbdnbd2372837283jfbjebf8384384&quot; //your registered application’s client_id<br />
String userMediaUrl = &quot;https://api.instagram.com/v1/users/&quot; + instagramUserId + &quot;/media/recent/?client_id=&quot;+clientId<br />
URL url = new URL(queryString)<br />
return url.text<br />
[/code]

To learn more about it you can follow the link http://instagram.com/developer

FOUND THIS USEFUL? SHARE IT

comments (1 “Instagram API: Fetch user’s followers and media”)

Leave a Reply

Your email address will not be published. Required fields are marked *