{"id":12731,"date":"2014-04-04T01:57:21","date_gmt":"2014-04-03T20:27:21","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=12731"},"modified":"2014-04-04T01:57:21","modified_gmt":"2014-04-03T20:27:21","slug":"instagram-api-fetch-users-followers-and-media","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/instagram-api-fetch-users-followers-and-media\/","title":{"rendered":"Instagram API: Fetch user&#8217;s followers and media"},"content":{"rendered":"<p>In my <a title=\"Using Instagram API to login via Grails\" href=\"http:\/\/www.tothenew.com\/blog\/using-the-instagram-login-api-via-grails\/\" target=\"_blank\">previous blog<\/a> we learnt how to integrate Instagram login functionality in a Grails web app. Now we will see how to get Instagram user&#8217;s followers and media.<\/p>\n<p>Once a user is logged in via the Instagram login API, we get a JSON response containing the logged in user&#8217;s profile information in JSON Format. A sample JSON is as follows:<\/p>\n<p>[code]&lt;br \/&gt;<br \/>\nJSONObject userInfo = [&lt;br \/&gt;<br \/>\n                         user:[&lt;br \/&gt;<br \/>\n                            id:212545455,&lt;br \/&gt;<br \/>\n                            profile_picture:http:\/\/images.ak.instagram.com\/profiles\/profile_120652151_75sq_545454125.jpg,&lt;br \/&gt;<br \/>\n                            username:abcdefg45,&lt;br \/&gt;<br \/>\n                            bio:,&lt;br \/&gt;<br \/>\n                            website:,&lt;br \/&gt;<br \/>\n                            full_name:abcd xyz&lt;br \/&gt;<br \/>\n                         ],&lt;br \/&gt;<br \/>\n                         access_token:122545212145.ddjsjdaa.002jdjwsdjdjdjndf7458&lt;br \/&gt;<br \/>\n                   ]&lt;\/p&gt;<br \/>\n&lt;p&gt;String instagramUserId = userInfo.user.id&lt;br \/&gt;<br \/>\nString accessToken = userInfo.access_token&lt;br \/&gt;<br \/>\n[\/code]<\/p>\n<p>Now using this information, we can get the followers of the Instagram user as follows:<\/p>\n<p>[code]&lt;br \/&gt;<br \/>\nString instagramFollowersUrl = &amp;quot;https:\/\/api.instagram.com\/v1\/users\/&amp;quot; + instagramUserId + &amp;quot;\/?access_token=&amp;quot; + accessToken&lt;br \/&gt;<br \/>\nURL url = new URL(queryString)&lt;br \/&gt;<br \/>\nreturn url.text&lt;br \/&gt;<br \/>\n[\/code]<\/p>\n<p>Too get all recent media posted by an Instagram user, the API call made is as follows:<\/p>\n<p>[code]&lt;\/p&gt;<br \/>\n&lt;p&gt;String clientId = &amp;quot;nbdnbd2372837283jfbjebf8384384&amp;quot; \/\/your registered application&#8217;s client_id&lt;br \/&gt;<br \/>\nString userMediaUrl = &amp;quot;https:\/\/api.instagram.com\/v1\/users\/&amp;quot; + instagramUserId + &amp;quot;\/media\/recent\/?client_id=&amp;quot;+clientId&lt;br \/&gt;<br \/>\nURL url = new URL(queryString)&lt;br \/&gt;<br \/>\nreturn url.text&lt;br \/&gt;<br \/>\n[\/code]<\/p>\n<p>To learn more about it you can follow the link <a href=\"http:\/\/instagram.com\/developer\">http:\/\/instagram.com\/developer<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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&#8217;s profile information in JSON Format. [&hellip;]<\/p>\n","protected":false},"author":72,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":24},"categories":[7],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/12731"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/72"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=12731"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/12731\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=12731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=12731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=12731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}