ランキングに戻る

dilame/instagram-private-api

TypeScript

NodeJS Instagram private API SDK. Written in TypeScript.

instagraminstagram-apiinstagram-clientinstagram-feedinstagram-private-apiinstagram-scraperinstagram-sdk
スター成長
スター
6.5k
フォーク
1.2k
週間成長
Issue
381
2k4k6k
2023年1月2024年3月2025年5月2026年7月
成果物npmnpm install instagram-private-api
README

NodeJS Instagram private API client

logo

Telegram Chat npm npm Join the chat at https://gitter.im/instagram-private-api/Lobby


Next Major Version

Nerix and I are excited to announce the next 3.x.x version of this library. It features an extended list of capabilities and is a significant release. We have substantially expanded the functionality and possibilities. The library has transformed into a monorepository and is now a set of libraries connected in an ecosystem. It consists of:

  • Android API
  • Web API
  • FBNS, Realtime

We've made some design decisions and simplified the state management process. Now, you can easily create a snapshot of the account state, save it in persistent storage, and restore a 1-to-1 copy with just one function call. With new realtime features, you can listen for new direct messages, notifications, and other events.

You can take a look at the type documentation for the next version by following this link – https://docs.igpapi.com

The new version is hosted in a private repository and access is paid. Members receive exhaustive support for the entire integration process.

Contact me in telegram or email for details.

Table of Contents

Install

From npm

npm install instagram-private-api

From github

npm install github:dilame/instagram-private-api

This package uses url-regex-safe (GitHub) to check for links when sending direct messages. By default, the safe regex engine re2 is not installed. ⚠ It's highly recommended for you to install re2 by running npm install re2, else you will be vulnerable to CVE-2020-7661.

Support us

If you find this library useful for you, you can support it by donating any amount

BTC: 1Dqnz9QuswAvD3t7Jsw7LhwprR6HAWprW6

Examples

You can find usage examples here.

Note for JavaScript users: As of Node v.13.5.0, there isn't support for ESModules and the 'import'-syntax. So you have to read the imports in the examples like this:

import { A } from 'b'const { A } = require('b')

import { IgApiClient } from 'instagram-private-api';
import { sample } from 'lodash';

const ig = new IgApiClient();
// You must generate device id's before login.
// Id's generated based on seed
// So if you pass the same value as first argument - the same id's are generated every time
ig.state.generateDevice(process.env.IG_USERNAME);
// Optionally you can setup proxy url
ig.state.proxyUrl = process.env.IG_PROXY;
(async () => {
  // Execute all requests prior to authorization in the real Android application
  // Not required but recommended
  await ig.simulate.preLoginFlow();
  const loggedInUser = await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);
  // The same as preLoginFlow()
  // Optionally wrap it to process.nextTick so we dont need to wait ending of this bunch of requests
  process.nextTick(async () => await ig.simulate.postLoginFlow());
  // Create UserFeed instance to get loggedInUser's posts
  const userFeed = ig.feed.user(loggedInUser.pk);
  const myPostsFirstPage = await userFeed.items();
  // All the feeds are auto-paginated, so you just need to call .items() sequentially to get next page
  const myPostsSecondPage = await userFeed.items();
  await ig.media.like({
    // Like our first post from first page or first post from second page randomly
    mediaId: sample([myPostsFirstPage[0].id, myPostsSecondPage[0].id]),
    moduleInfo: {
      module_name: 'profile',
      user_id: loggedInUser.pk,
      username: loggedInUser.username,
    },
    d: sample([0, 1]),
  });
})();

Basic concepts

You can find documentation in the docs folder. Consider starting in IgApiClient (index module), the root class.

You'll often see ig in the docs. This just refers to the client, an instance of IgApiClient holding the state for one user.

import { IgApiClient } from 'instagram-private-api';

// This is the general convention on how to name the client
//    vv
const ig = new IgApiClient();

// login, load a session etc.

Repositories

Repositories implement low-level operations - every method sends exactly one api-request.

You access repositories on the client (IgApiClient) by their lower-case (camelCase) name without the Repository suffix. For example, you access the instance of AddressBookRepository by ig.addressBook.

Feeds

Feeds represent paginated endpoints like a user's feed (UserFeed). Think of feeds like (async-)iterators/streams/observables (in fact feeds are async iterable and observable (feed.item$)). Every feed is accessible via ig.feed.feedName() (camelCase name). ig.feed is the FeedFactory that creates feeds for you connected to the instance of ig.

Most of the feeds require initialization parameter(s), like a user-pk (id).

Services

Services will help you to maintain some actions without calling a couple repository methods or perform complex things like pre and postlogin flow simulations or photo/video publishing.

Debugging

In order to get debug infos provided by the library, you can enable debugging. The prefix for this library is ig. To get all debug logs (recommended) set the namespace to ig:*.

Node

In Node you only have to set the environment variable DEBUG to the desired namespace. Further information

Contribution

If you need features that is not implemented - feel free to implement and create PRs!

Plus we need some documentation, so if you are good in it - you are welcome.

Setting up your environment is described here.

Useful links

instagram-id-to-url-segment - convert the image url fragment to the media ID

Special thanks

  • Richard Hutta, original author of this library. Thanks to him for starting it.

Thanks to contributors

  • Nerixyz, for writing a huge amount of code for this library.
関連リポジトリ
mvanhorn/last30days-skill

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

PythonPyPIMIT Licenseai-promptsclaude
53k4.6k
DIYgod/RSSHub

🧡 Everything is RSSible

TypeScriptnpmGNU Affero General Public License v3.0rsstwitter
docs.rsshub.app
45.3k10k
imputnet/cobalt

best way to save what you love

SvelteGNU Affero General Public License v3.0downloaderreddit
cobalt.tools
41.7k3.6k
GorvGoyl/Clone-Wars

100+ open-source clones of popular sites like Airbnb, Amazon, Instagram, Netflix, Tiktok, Spotify, Whatsapp, Youtube etc. See source code, demo links, tech stack, github stars.

GNU Affero General Public License v3.0clonetiktok
gourav.io/clone-wars
36.3k3.3k
transloadit/uppy

The next open source file uploader for web browsers :dog:

TypeScriptnpmMIT Licensetusresumable
uppy.io
30.9k2.1k
InstaPy/InstaPy

📷 Instagram Bot - Tool for automated Instagram interactions

PythonPyPIGNU General Public License v3.0instagramclarifai
18k3.9k
Datalux/Osintgram

Osintgram is a OSINT tool on Instagram. It offers an interactive shell to perform analysis on Instagram account of any users by its nickname

PythonPyPIGNU General Public License v3.0osintosint-python
13.6k3k
Instagram/IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.

Objective-CMIT Licenseuicollectionviewios
instagram.github.io/IGListKit/
13.1k1.5k
instaloader/instaloader

Download pictures (or videos) along with their captions and other metadata from Instagram.

PythonPyPIMIT Licenseinstagraminstagram-client
instaloader.github.io
12.9k1.6k
megadose/holehe

holehe allows you to check if the mail is used on different sites like twitter, instagram and will retrieve information on sites with the forgotten password function.

PythonPyPIGNU General Public License v3.0information-gatheringosint
11.8k1.5k
mrousavy/react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.

TypeScriptnpmMIT Licensereact-nativecamera
visioncamera.margelo.com
9.5k1.4k
mendel5/alternative-front-ends

Overview of alternative open source front-ends for popular internet platforms (e.g. YouTube, Twitter, etc.)

GNU Affero General Public License v3.0frontendinvidious
9k235