Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram ?__a=1 not working anymore

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?

like image 605
Olivier Van Bulck Avatar asked Apr 13 '18 08:04

Olivier Van Bulck


2 Answers

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:

https://www.instagram.com/username/channel/?__a=1

like image 91
MattF Avatar answered Dec 17 '22 15:12

MattF


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);
like image 22
Alexander C Avatar answered Dec 17 '22 16:12

Alexander C