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.
Table of Contents- Install Support us Examples Basic Concepts Feeds Repositories Services Contribution Useful Links Special Thanks Thanks to Contributors End User License Agreement (EULA)
From npm
npm install instagram-private-api
From github
npm install github:dilame/instagram-private-api
url-regex-safe
re2
re2
npm install re2
Support us
If you find this library useful for you, you can support it by donating any amount
BTC: 1Dqnz9QuswAvD3t7Jsw7LhwprR6HAWprW6
ExamplesYou 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
docs
IgApiClient
index
ig
IgApiClient
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.
IgApiClient
IgApiClient
Repository
AddressBookRepository
ig.addressBook
Feeds
UserFeed
feed.item$
ig.feed.feedName()
ig.feed
FeedFactory
ig
FeedFactory
ig.feed
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.
IgApiClient
Debugging
ig
ig:*
Node
DEBUG
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 linksinstagram-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.