Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Instagram graphql?

I'm using the following query https://www.instagram.com/graphql/query/?query_id=17851374694183129&id={acountId}&first=1000&after={cursor} to get an user followers. The information I need is the followed_by_count index that's only available per user on https://www.instagram.com/{username}?__a=1

Is there a query_id that includes the followed_by_count in the result?

like image 769
Valdir Avatar asked Aug 20 '17 21:08

Valdir


People also ask

How to scrape data from Instagram using GraphQL?

This is because Instagram first loads the layout and all the data it needs from its internal GraphQL API and then puts the data in the correct layout. We could scrape this data directly if we queried Instagrams GraphQL endpoint directly by adding "/?__a=1" onto the end of the URL. For example:

What is the Instagram graph API?

The Instagram Graph API allows Instagram Professionals — Businesses and Creators — to use your app to manage their presence on Instagram.

How can I see the same GraphQL query for Instagram posts?

Open Inspector in Chrome, visit Instagram and scroll through the posts, you'll see the same GraphQL queries with query_hash. I'm not sure what query_hash value means exactly, but they're static for each type of query it seems.

What is the best API for building an Instagram app?

If you are building an app for consumers or you only need to get an app user's basic profile information, photos, and videos, consider the Instagram Basic Display API instead. The API is built on the Facebook Graph API.


1 Answers

This query_id code https://www.instagram.com/graphql/query/?query_id=17851374694183129&id=<user_id>&first=1000&after=<end_cursor> is designed to return ONLY media data it does NOT include user profile data.

The simplest solution is to use what IG uses on initial page requests:

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

Here is my RubyOnRails setup:

profile = JSON.parse(open("https://www.instagram.com/<ig_username>/?__a=1").read)

... now grab your variables:

profile.['graphql']['user']['profile_pic_url']
 
profile.['graphql']['user']['biography']

profile.['graphql']['user']['external_url']

profile.['graphql']['user']['edge_followed_by']['count']

profile.['graphql']['user']['edge_follow']['count']

profile.['graphql']['user']['id']

profile.['graphql']['user']['edge_owner_to_timeline_media']['count']

profile.['graphql']['user']['profile_pic_url']

profile.['graphql']['user']['profile_pic_url_hd']

And your followed_by_count is now ['graphql']['user']['edge_followed_by']['count']

like image 51
Mark Avatar answered Sep 28 '22 01:09

Mark