Instagram ?__a=1 not working anymore

我只是一个虾纸丫 提交于 2019-11-27 16:17:43

问题


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?


回答1:


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




回答2:


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);



回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/49812575/instagram-a-1-not-working-anymore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!