npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lskjs/instagram-private-api

v1.44.0

Published

Instagram private API wrapper for full access to instagram

Downloads

4

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

Me and Nerix are ready to announce the next 2.x.x version of this library. It has extended feature list. It's a big release. We have significantly expanded the functionality and capabilities. The library turned into a monorepository and now it's a set of libraries, connected in an ecosystem. It consists of

  • Android API
  • Web API
  • FBNS, Realtime

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

The new version is hosted in private repository. Access is paid. Members get basic support for installation, configuration, and usage. We also will try to react on your feature requests.

You can contact me in telegram or email for details.

AD: SaaS Instagram API

Excited to announce SaaS Instagram API http://open.igpapi.com/

It uses OpenAPI specification, so you can generate SDK for any programming language in several minutes.

You can use it right in the browser without need to have a server.

You can even use it in React Native. Yes, without bridges.

It's free for a while, until it's stable. The function set is poor now, because, to be honest i'm not sure if there's a demand for it. So if you would like to use it, have feature-requests or bug reports - please contact me - i'll implement things you need very fast.

Table of Contents

Install

From npm

npm install instagram-private-api

From github

npm install github:dilame/instagram-private-api

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 './index';
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]),
  });
})();

Signup via phone example

import { IgApiClient } from './index';
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 phone_number: string = '79178272727';
  await ig.account.sendSignupSmsCode(phone_number);
  const verification_code: string = '123456';
  await ig.account.validateSignupSmsCode(phone_number, verification_code);
  const loggedInUser = await ig.account.createValidated({
    phone_number,
    verification_code,
    username: 'something',
    first_name: 'Someone',
    password: 'password',
    year: '1995',
    month: '05',
    day: '05',
  });

  // 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

Feeds

Feed allows you to get data. Every feed is accessible via ig.feed.feedName. See nice example and learn how to work with library feeds.

Available feeds key list:

accountFollowers, accountFollowing, news, discover, pendingFriendships, blockedUsers, directInbox, directPending, directThread, user, tag, location, mediaComments, reelsMedia, reelsTray, timeline, musicTrending, musicSearch, musicGenre, musicMood, usertags, saved

Most of the feeds requires initialization parameter, like user pk. Check autogenerated docs, every feed doc link starts with feeds/ and contains constructor with argument if needed.

Repositories

Repositories implements low-level atomic operations. Any repository method must make at most one api-request. There is repository listing below, so you can get information about methods of each repository from our autogenerated docs.

Keys is a little hints, with it you will be able to get access to repository via ig.key.

| Key | Repository class documentation | | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | account | AccountRepository | | attribution | AttributionRepository | | challenge | ChallengeRepository | | consent | ConsentRepository | | creatives | CreativesRepository | | direct | DirectRepository | | directThread | DirectThreadRepository | | discover | DiscoverRepository | | fbsearch | FbsearchRepository | | friendship | FriendshipRepository | | launcher | LauncherRepository | | linkedAccount | LinkedAccountRepository | | live | LiveRepository | | location | LocationRepository | | locationSearch | LocationSearch | | loom | LoomRepository | | media | MediaRepository | | music | MusicRepository | | news | NewsRepository | | qe | QeRepository | | qp | QpRepository | | tag | TagRepository | | upload | UploadRepository | | user | UserRepository | | zr | ZrRepository |

Services

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

| Key | Service class documentation | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | publish | PublishService | | search | SearchService | | simulate | SimulateService | | story | StoryService |

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

Browser

In the browser you have to set localStorage.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.