What is the new instagram json endpoint?
What is the new instagram json endpoint?
Instagram used to expose open data as json under the endpoint https:www.instagram.comusername__a1. This changed over night, the endpoint ins not available anymore. What is the new endpoint or what could be an alternative to this Thanks in advance
The endpoint does not exist anymore. Facebook is restricting APIs because of scandals. The data is still there of course, Instagrams frontend needs it, so the alternative right now is to scrape the page and find the json data there. Here is how I do it: Do an http get to to https:www.instagram.comusername. Look for the script tag which texts starts with window._sharedData . You can use regular expressions or a scraping library for this. The rest of the text except for the ; at the end is the json data you want. Cast the stringified json into json in order to access it like before. The first element in the ProfilePage key in the entry_data key corresponds exactly to the json returned by the old endpoint. Here is an example using Python: import requests from bs4 import BeautifulSoup import re import json r requests.gethttps:www.instagram.comgithub soup BeautifulSoupr.content scripts soup.find_allscript, typetextjavascript, textre.compilewindow._sharedData stringified_json scripts0.get_text.replacewindow._sharedData , :-1 json.loadsstringified_jsonentry_dataProfilePage0 Out1: ugraphql: uuser: ubiography: uHow people build software., ublocked_by_viewer: False, ...
It seems to be turned off, which is frustrating. It may be related to this. https:techcrunch.com20180404facebook-instagram-api-shut-down
In case youre seeking for the regex: script typetextjavascriptwindow._sharedData sS;script
Комментарии
Отправить комментарий