I've been using Instagram's undocumented API https://www.instagram.com/<user>/?__a=1
to get a public user feed on a website. Since a while now, this is not working anymore, probably because Facebook removed it. Is there an other way to get the data of an instagram account in a easy way?
-
1Instagram blocked __a=1 endpoint , checkout stackoverflow.com/questions/49265339/…– KolomoloboloApr 13, 2018 at 10:18
-
Same solution with Php I updated my answer yesterday. stackoverflow.com/questions/49458818/instagram-pb-full-res/…– xC0dexApr 13, 2018 at 11:32
-
Too bad it's blocked completely... It's public available info for god's sake... But I already knew that was going to be the case, it was just a matter of time since Facebook acquired Instagram... And I know it's blocked, I'm just wondering if anyone knows a solid alternative solution.– Olivier Van BulckApr 13, 2018 at 12:03
-
@OlivierVanBulck I am facing the same problem. Would you please give instagram example with pagination?– Purvik DhorajiyaApr 24, 2018 at 8:55
-
2It seems to work again indeed. Maybe they added it again because of complaints.– Olivier Van BulckSep 18, 2019 at 12:41
5 Answers
I built a small server which does that transformation. You'll receive the instagram data as before with ?__a=1 (as JSON ) - have fun 😊
https://www.instapi.io/u/<username>
https://www.instapi.io/u/appwithus
EDIT 12/2020: Unfortunately the service is no longer available
-
Do the cursors work? I did it with a GET variable called max_id and gave that one the next cursor but that's not working here right now? Apr 16, 2018 at 21:53
-
Thats not possible, you can just provide your username, no additional parameters– chrisbyApr 17, 2018 at 7:54
-
2
-
1@wiesson, he is getting data with the help of web scrapper. you can see my answer below to get that code. May 11, 2018 at 7:07
-
6
Edit 15/03 NOT WORKING ANYMORE Seems like instagram changed again their API, now it gives a CORS error.
As of 2 february 2021, I have found a solution
Instead of using https://www.instagram.com/username/?__a=1 which it asks for a login.
Justing adding a /channel seems to make it work, like so:
-
The original url without /channel gives the same result now I believe? Feb 3, 2021 at 8:25
-
It does, but without /channel it sends a login page instead of the JSON in a GET request– MattFFeb 3, 2021 at 16:46
-
How do you get the data? I've tried with
resp.graphql.user.edge_owner_to_timeline_media.edges
and I get the following:TypeError: Cannot read property 'graphql' of undefined at index.js:8
– cyruslkFeb 9, 2021 at 2:59 -
data getting in postman using instagram.com/username/channel/?__a=1 url but not getting in react.Js project while calling api using fetch().– PragneshAug 10, 2021 at 11:59
-
There is a JSON data in https://www.instagram.com/<user>/
.
You can use regexp to find what you need.
Sample
// This regexp gets widest possible dict around "profile_pic_url"
// but inside tag <script type="text/javascript">...</script>
let r = new RegExp('<script type="text\/javascript">' +
'([^{]+?({.*profile_pic_url.*})[^}]+?)' +
'<\/script>');
let source = document.documentElement.outerHTML;
let jsonStr = source.match(r)[2];
let data = JSON.parse(jsonStr);
console.log('data', data);
let oldVariantOfData = data['entry_data']['ProfilePage'][0];
console.log('oldVariantOfData', oldVariantOfData);
-
Great option! Though it's not working perfectly for me. I need the info about the posts from that user. The json has the first 12 and a next cursor, but for what I know, there is no endpoint that I can use the next cursor on now. It seems the page is ignoring the information for pagination. Is there a way to get the rest of the posts in a new call? Apr 16, 2018 at 9:16
-
-
In order to get 12 posts I use SlimerJS. First I got 12 posts, and read next cursor. Then I simulate scroll down action and capture respons with json, which url contains this cursor.I get new 12 posts from it and next cursor. etc. Apr 16, 2018 at 17:37
The same response is attached in the html response of the profile url, I perform this temporal solution (when I can't use the API) in python:
url_recent_media = 'https://www.instagram.com/%s/' % instagram_id
response = urllib2.urlopen(url_recent_media)
insta_html = response.read()
insta_html_split = insta_html.split('"ProfilePage":[')
if len(insta_html_split) > 1:
insta_html_split_2 = insta_html_split[1].split(']},"gatekeepers"')
if len(insta_html_split_2) > 1:
json_dict = json.loads(insta_html_split_2[0])
I hope this help you.
-
It'd probably help, but too bad it's nothing more than a temporary solution. Whenever the code change, it won't work anymore... And Facebook will probably change it fast enough... Apr 13, 2018 at 12:05
you can try without using instagram API.
import json, urllib2
img_dicts = []
url = 'https://www.instagram.com/{}/'.format(instagram_username)
try:
r = urllib2.urlopen(url, timeout=10.0)
instagram_html = r.read()
instagram_html_data = instagram_html.split('"ProfilePage":[')
if len(instagram_html_data) > 1:
instagram_html_final_data = instagram_html_data[1].split(']},"gatekeepers"')
if len(instagram_html_final_data) > 1:
json_dict = json.loads(instagram_html_final_data[0])
media = json_dict['graphql']['user']['edge_owner_to_timeline_media']['edges']
for obj in media:
img_dicts.append({
'id': obj['node']['id'],
'caption': obj['node']['edge_media_to_caption']['edges'][0]['node']['text'],
'imgurl_standard': obj['node']['display_url'],
'imgurl_lower': obj['node']['thumbnail_resources'][4]['src'],
'imgurl_thumb': obj['node']['thumbnail_resources'][3]['src']
})
img_dicts
will give you images in different quality and caption of instagram post.