question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using a new Instagram endpoint to get hashtag posts - Potentially a feature suggestion

See original GitHub issue

I 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: image

I see in Chrome network inspector, that the Insta webpage can make this POST call and get the following stats/response:

image image image

What am i doing wrong with my POST request to obtain my 302 response? Thanks in advance!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
nibu147commented, Mar 20, 2022

hello, any updates on this? any planned new release? many thanks!

0reactions
BugDominatorcommented, Aug 31, 2022

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”:“”}

Read more comments on GitHub >

github_iconTop Results From Across the Web

11 Ways to Use Instagram's API for Your Business [Examples]
Use the Instagram API to find data from specific hashtags, pull images from certain hashtags, and publish them on your site in real-time....
Read more >
Hashtag Search - Instagram Platform - Meta for Developers
To get all of the photos and videos that have a specific hashtag, first use the /ig_hashtag_search endpoint and include the hashtag and...
Read more >
Learn How to Use Instagram API - Verloop.io
A complete guide to using Instagram API for supporting users and getting followers, with many examples. Improve customer engagement with ...
Read more >
Updates to the Sensitive Content Control - Instagram
Today, we are announcing that you can control the amount of sensitive content and accounts you see on Instagram.
Read more >
Top New Instagram Updates and Features in 2022
Try EmbedFeed and display Instagram content from your feed, mentions, or hashtags on your website. Start a 7-day free trial. All features ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found