Instagram

Instagram API & Data Access

Unofficial | šŸ‘‰ Official Instagram Website: https://www.instagram.com | šŸ‘„ Contributors: steve

Notes

These are unofficial Instagram API endpoints useful for scraping public data such as posts, comments, followers, likers and email addresses. They are made available for unofficial use and experimentation, such as for security research, use at your own risk!

Most of these endpoints are presumed to work with Instagram’s mobile app, meaning that these endpoints are unlikely to change too much as mobile clients tend to stick around in the wild for a while. Hence, it should be safe to assume these won’t change too much over the next few years.

Session ID

Most of these endpoints require you to enter a Session ID corresponding to a logged in session of a valid Instagram account. It’s possible that using your real Instagram account’s session ID on this system via proxies may result in your real account being flagged or banned. Please plan accordingly when choosing an Instagram account to use as your session ID for these endpoints.

Getting Your Session ID

If you’re comfortable entering your username and password, you can use the Instagram Authentication endpoint to get your Session ID.

If you’d prefer to do a little work, you can use your logged-in Instagram account’s Session ID. To see how to do this, please see How to Find Your Instagram Session ID article for step-by-step instructions on how to get your Instagram Session ID.

Reusing Your Session ID

We suggest using workflows to automate repeated requests to Instagram for batch processing and result aggregation. Please see How to Use Your Instagram Session ID with Workflows for more information.

Rate Limiting

Instagram is known to throttle requests if you exceed 1 request per second. This will usually result in a 429 error code.

Read Only

These endpoints are “read only” and only allow you to scrape data. If you need to automate “posting” to Instagram or other activities like following, please take a look at these Python libraries for additional functionality:

Official API

Instagram used to have a more open official API, but has recently made some changes to its API & approval policies as of 2018. They have revoked access to existing apps and now require a much stricter approval process to access any amount of data from Instagram (even if public or from your own account).

Pagination

Most endpoints that support pagination will prompt for an optional Max ID field (or similar), which tell Instagram the ID to start from on the next request.

To paginate over a result set, you’ll want to execute an endpoint with a blank Max ID first, download the response, and then take note of the Max ID field returned from the initial response.

Copy the Max ID from the initial response and use it in the next request to get the next page of your results. Keep repeating this process until you stop getting new results back. Note that in many cases Instagram may cap the number of results you can get back to 1,000.

Notable Fields

When you examine the response from Instagram, you may find this information helpful for one or more of the endpoints here.

  • taken_at When the post was created, formatted as an epoch. You can convert it to a human readable timestamp with an epoch converter.
  • code Instagram URL code that can be used to construct the URL to the Instagram post on the web by prepending https://www.instagram.com/p/ to it.

Sample Data

Below is a sample JSON snippet for an Instagram user you should follow. You can also download aggregate results together in CSV format.

{
  "pk": 7458276152,
  "username": "stevesiedata",
  "full_name": "Stevesie Data",
  "is_private": false,
  "profile_pic_url": "https://scontent-lga3-1.cdninstagram.com/vp/00020fe765cbf0625e150df566fd22be/5DC8B713/t51.2885-19/s150x150/29736960_232489090821173_327652519457062912_n.jpg?_nc_ht=scontent-lga3-1.cdninstagram.com",
  "profile_pic_id": "1753021368734043333_7458276152",
  "is_verified": false,
  "has_anonymous_profile_picture": false,
  "media_count": 7,
  "follower_count": 38,
  "following_count": 12,
  "following_tag_count": 0,
  "biography": "šŸš€ Data for Startups\nšŸ‘‰ https://stevesie.com",
  "external_url": "https://stevesie.com/",
  "external_lynx_url": "https://l.instagram.com/?u=https%3A%2F%2Fstevesie.com%2F&e=ATPqY9rvDoWvyapqyKe1NAQ2SGKu4qD87AxlrsHPqMFmUKXq0NmJx8FHcFC4QYiqrMMSFjB6",
  "total_igtv_videos": 0,
  "total_ar_effects": 0,
  "usertags_count": 0,
  "is_interest_account": true,
  "hd_profile_pic_url_info": {...},
  "has_highlight_reels": false,
  "can_be_reported_as_fraud": false,
  "is_potential_business": true,
  "auto_expand_chaining": false,
  "highlight_reshare_disabled": false
}

Articles

Scrape Instagram Posts by Hashtag, Location & Date Published Aug. 2, 2019, 2:02 a.m. by steve
How to Find Your Instagram Session ID Published July 17, 2019, 8:24 p.m. by steve
How to Use Your Instagram Session ID with Workflows Published July 17, 2019, 7:57 p.m. by steve
How to Download Instagram Stories Published Oct. 27, 2018, 11:09 a.m. by steve