Using a new Instagram endpoint to get hashtag posts - Potentially a feature suggestion
See original GitHub issueI am looking to implement a new Hashtag.get_posts() function which may be useful to the community as a new feature, but first i have a question.
I am unable to get Hashtag.get_posts() to work with my authenticated session as mentioned in my other question, because using get_hashtag_posts
doesn’t return new posts when max_id is set for page 2, 3 and 4 etc. The new endpoint i want to use is:
POST https://i.instagram.com/api/v1/tags/hashtag_name/sections/
From the instagram webpage, i can see it can obtain posts from a hashtag list. Here is my sample code:
` def get_hashtag_sections(self, next_max_id): import http.client # pylint:disable=protected-access http.client._MAXHEADERS = 200 session = self._session session.get(‘https://www.instagram.com/web/__mid/’) cookies = session.cookies.get_dict() csrf_token = cookies[‘csrftoken’] session.headers.update({‘X-CSRFToken’: csrf_token}) session.headers.update({‘x-instagram-ajax’: “238ee7baa9c1”}) session.headers.update({“x-ig-www-claim”: “hmac.AR2nh9sxfnOaFqar3sYyhAM59aLB6hcF7WoqNJe2MJvmHiWi”}) session.headers.update({“x-ig-app-id”: “936619743392459”}) session.headers.update({“content-type”: “application/x-www-form-urlencoded”}) session.headers.update({“authority”: “i.instagram.com”})
data = {'include_persistent': 0, 'max_id': next_max_id, 'page': 1, 'surface': 'grid', 'tab': 'recent'}
posts = session.post('https://i.instagram.com/api/v1/tags/%s/sections/?__a=1' % "arcadeofblackandwhite",
data=data, allow_redirects=False)
try:
resp_json = posts.json()
except json.decoder.JSONDecodeError:
raise ConnectionException("Error: JSON decode fail")
except Exception as e:
raise ConnectionException("Error: %s" % str(e))
`
When i run the code above, the posts
response is 302, a redirect. I have pasted a view of the posts variable data below:
I see in Chrome network inspector, that the Insta webpage can make this POST call and get the following stats/response:



What am i doing wrong with my POST request to obtain my 302 response? Thanks in advance!
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
hello, any updates on this? any planned new release? many thanks!
I am solved it out, you can try this.
add the following key to request headers. {“x-csrftoken”: “”, “x-asbd-id”: “”, “x-ig-app-id”: “”, “x-ig-www-claim”: “hmac.”, “x-instagram-ajax”:“”}