Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram ?__a=1&max_id=<end_cursor> isn't working for public user feeds

Tags:

api

instagram

I've been using Instagram's undocumented API https://www.instagram.com/<user>/?__a=1 to get a public user feed.

I was also able to get multiple pages via their max_id query parameter like so: https://www.instagram.com/<user>/?__a=1&max_id=<end_cursor>

end_cursor = json_response.graphql.user.edge_owner_to_timeline_media.page_info.end_cursor

(yes, "has_next_page" is true)

They had a recent change to their JSON format and I think they might have broken other functionality.

The "end_cursor" is still there but when I use it I just get back the same Instagram posts as if I wasn't using it.

Just to make sure I'm clear, my issue is that the max_id=<end_cursor> doesn't seem to work anymore for a public user feed. I can still get the first 12 posts, but no more after that.

Anyone else seeing this problem?

here's a JSFiddle example of what I mean: https://jsfiddle.net/LLsg91ja/33/

like image 548
Francisc0 Avatar asked Mar 13 '18 20:03

Francisc0


People also ask

How do I get JSON data from Instagram?

Enter the email address where you'd like to receive a link to your data. Click next to HTML or JSON to select the format you'd like to receive your data in, then click Next. Enter your Instagram account password and click Request download.

Does Instagram allow scraping?

You may not use the Instagram service for any illegal or unauthorized purpose. ... You must not crawl, scrape, or otherwise cache any content from Instagram including but not limited to user profiles and photos. You must not create or submit unwanted email or comments to any Instagram members ("Spam").

Does Instagram have an API?

The Instagram Basic Display API allows users of your app to get basic profile information, photos, and videos in their Instagram accounts. The API can be used to access any type of Instagram account but only provides read-access to basic data.

How do you make a hash query on Instagram?

The Query HashNavigate to the Instagram account you want to show pictures from and open the Developer Tools and click on the Network tab. With the Network tab open, refresh the Instagram page you are viewing. Then click on the XHR filter. Here's what it looks like for me in the latest Firefox browser.


1 Answers

04-14-2018 - NO LONGER WORKING - INSTAGRAM DEPRECATED THE '?__a=1' & '?query_id=17888483320059182' - THIS NO LONGER WORKS!

Okay take a look at this for media pagination:

https://instagram.com/graphql/query/?query_id=17888483320059182&id=<user_id>&first=12&after=<end_cursor>

This returns:

['data']['user']['edge_owner_to_timeline_media']['page_info']['end_cursor']

And Media:

['data']['user']['edge_owner_to_timeline_media']['edges']

the 'query_id' is static now so just use: 17888483320059182

'id' is the "instagram user id" so you have to use ?__a=1 to grab ['graphql']['user']['id']

'first' is the number of photos you desire returned. Just use 12 to keep the media return the same.

'after' is the new 'max_id' for use ['data']['user']['edge_owner_to_timeline_media']['page_info']['end_cursor']

I'll test more and respond later.

Responding Later:

It is believed 'pagination' using ?__a=1 has been deprecated. If true then there is no answer which can solve the op's direct question using ?__a=1 for Instagram pagination.

But the code provided in this answer will provide the pagination of Instagram media which does provide the results the op was seeking.

The answer incorporates the 'instagram graphql api' which is the current api (and not the json ?__a=1 hack) so this answer should provide some stability for now.

As used on my live site:

Grab the id=<instagram_user_id> prior the Instagram media request:

profile = https://www.instagram.com/<instagram_username>/?__a=1

media = https://instagram.com/graphql/query/?query_id=17888483320059182&id=<profile['graphql']['user']['id']>&first=12&after=<end_cursor>

like image 84
Mark Avatar answered Oct 04 '22 15:10

Mark