NodeJS Instagram private API client
![logo](https://cloud.githubusercontent.com/assets/1809268/15931032/2792427e-2e56-11e6-831e-ffab238cc4a2.png)
![Join the chat at https://gitter.im/instagram-private-api/Lobby](https://badges.gitter.im/Join%20Chat.svg)
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 './src';
import { sample } from 'lodash';
const ig = new IgApiClient();
ig.state.generateDevice(process.env.IG_USERNAME);
ig.state.proxyUrl = process.env.IG_PROXY;
(async () => {
await ig.simulate.preLoginFlow();
const loggedInUser = await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);
process.nextTick(async () => await ig.simulate.postLoginFlow());
const userFeed = ig.feed.user(loggedInUser.pk);
const myPostsFirstPage = await userFeed.items();
const myPostsSecondPage = await userFeed.items();
await ig.media.like({
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
.
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.
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.