Instagram API: Fetch user’s followers and media
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: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 />
Now using this information, we can get the followers of the Instagram user as follows:
<br /> String instagramFollowersUrl = "https://api.instagram.com/v1/users/" + instagramUserId + "/?access_token=" + 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> <p>String clientId = "nbdnbd2372837283jfbjebf8384384" //your registered application's client_id<br /> String userMediaUrl = "https://api.instagram.com/v1/users/" + instagramUserId + "/media/recent/?client_id="+clientId<br /> URL url = new URL(queryString)<br /> return url.text<br />
To learn more about it you can follow the link http://instagram.com/developer
Leave all unnecessary tags!