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:

<br />
JSONObject userInfo = [<br />
                         user:[<br />
                            id:212545455,<br />
                            profile_picture:,<br />
                            username:abcdefg45,<br />
                            bio:,<br />
                            website:,<br />
                            full_name:abcd xyz<br />
                         ],<br />
                         access_token:122545212145.ddjsjdaa.002jdjwsdjdjdjndf7458<br />
<p>String instagramUserId =<br />
String accessToken = userInfo.access_token<br />

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

<br />
String instagramFollowersUrl = &quot;; + instagramUserId + &quot;/?access_token=&quot; + accessToken<br />
URL url = new URL(queryString)<br />
return url.text<br />

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

<p>String clientId = &quot;nbdnbd2372837283jfbjebf8384384&quot; //your registered application's client_id<br />
String userMediaUrl = &quot;; + instagramUserId + &quot;/media/recent/?client_id=&quot;+clientId<br />
URL url = new URL(queryString)<br />
return url.text<br />

To learn more about it you can follow the link

Tag -


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

Leave a comment -