1 | # NodeJS Instagram private API client
|
2 |
|
3 | ![logo](https://cloud.githubusercontent.com/assets/1809268/15931032/2792427e-2e56-11e6-831e-ffab238cc4a2.png)
|
4 |
|
5 | [![Telegram Chat](https://img.shields.io/badge/telegram-join%20chat-informational.svg)](https://t.me/igpapi)
|
6 | [![npm](https://img.shields.io/npm/dm/instagram-private-api.svg?maxAge=600)](https://www.npmjs.com/package/instagram-private-api)
|
7 | [![npm](https://img.shields.io/npm/l/instagram-private-api.svg?maxAge=600)](https://github.com/huttarichard/instagram-private-api/blob/master/LICENSE)
|
8 | [![Join the chat at https://gitter.im/instagram-private-api/Lobby](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/instagram-private-api/Lobby)
|
9 |
|
10 | ---
|
11 |
|
12 | # Next Major Version
|
13 |
|
14 | [Nerix](https://github.com/Nerixyz) and I are excited to announce the next 3.x.x version of this library.
|
15 | It features an extended list of capabilities and is a significant release.
|
16 | We have substantially expanded the functionality and possibilities.
|
17 | The library has transformed into a monorepository and is now a set of libraries connected in an ecosystem.
|
18 | It consists of:
|
19 |
|
20 | - Android API
|
21 | - Web API
|
22 | - FBNS, Realtime
|
23 |
|
24 | We've made some design decisions and simplified the state management process.
|
25 | 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.
|
26 | With new realtime features, you can listen for new direct messages, notifications, and other events.
|
27 |
|
28 | You can take a look at the type documentation for the next version by following this link – [https://docs.igpapi.com](https://docs.igpapi.com/)
|
29 |
|
30 | The new version is hosted in a private repository and access is paid.
|
31 | Members receive exhaustive support for the entire integration process.
|
32 |
|
33 | Contact me in [telegram](https://t.me/bowzee) or [email](mailto:dilame.bowzee@gmail.com) for details.
|
34 |
|
35 | # Table of Contents
|
36 |
|
37 | - [Install](#install)
|
38 | - [Support us](#support-us)
|
39 | - [Examples](#examples)
|
40 | - [Basic Concepts](#basic-concepts)
|
41 | - [Feeds](#feeds)
|
42 | - [Repositories](#repositories)
|
43 | - [Services](#services)
|
44 | - [Contribution](#contribution)
|
45 | - [Useful Links](#useful-links)
|
46 | - [Special Thanks](#special-thanks)
|
47 | - [Thanks to Contributors](#thanks-to-contributors)
|
48 | - [End User License Agreement (EULA)](#end-user-license-agreement-eula)
|
49 |
|
50 | # Install
|
51 |
|
52 | From npm
|
53 |
|
54 | ```
|
55 | npm install instagram-private-api
|
56 | ```
|
57 |
|
58 | From github
|
59 |
|
60 | ```
|
61 | npm install github:dilame/instagram-private-api
|
62 | ```
|
63 |
|
64 | This package uses [`url-regex-safe`](https://www.npmjs.com/package/url-regex-safe) ([GitHub](https://github.com/spamscanner/url-regex-safe)) to check for links when sending direct messages.
|
65 | By default, the **safe** regex engine [`re2`](https://github.com/uhop/node-re2) is **not** installed.
|
66 | ⚠ It's highly recommended for you to install `re2` by running `npm install re2`, else you _will_ be vulnerable to [CVE-2020-7661](https://nvd.nist.gov/vuln/detail/CVE-2020-7661).
|
67 |
|
68 | # Support us
|
69 |
|
70 | If you find this library useful for you, you can support it by donating any amount
|
71 |
|
72 | BTC: 1Dqnz9QuswAvD3t7Jsw7LhwprR6HAWprW6
|
73 |
|
74 | # Examples
|
75 |
|
76 | You can find usage examples [here](examples).
|
77 |
|
78 | _Note for JavaScript users:_
|
79 | As of Node v.13.5.0, there isn't support for ESModules and the 'import'-syntax.
|
80 | So you have to read the imports in the examples like this:
|
81 |
|
82 | `import { A } from 'b'` ➡ `const { A } = require('b')`
|
83 |
|
84 | ```typescript
|
85 | import { IgApiClient } from 'instagram-private-api';
|
86 | import { sample } from 'lodash';
|
87 |
|
88 | const ig = new IgApiClient();
|
89 | // You must generate device id's before login.
|
90 | // Id's generated based on seed
|
91 | // So if you pass the same value as first argument - the same id's are generated every time
|
92 | ig.state.generateDevice(process.env.IG_USERNAME);
|
93 | // Optionally you can setup proxy url
|
94 | ig.state.proxyUrl = process.env.IG_PROXY;
|
95 | (async () => {
|
96 | // Execute all requests prior to authorization in the real Android application
|
97 | // Not required but recommended
|
98 | await ig.simulate.preLoginFlow();
|
99 | const loggedInUser = await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);
|
100 | // The same as preLoginFlow()
|
101 | // Optionally wrap it to process.nextTick so we dont need to wait ending of this bunch of requests
|
102 | process.nextTick(async () => await ig.simulate.postLoginFlow());
|
103 | // Create UserFeed instance to get loggedInUser's posts
|
104 | const userFeed = ig.feed.user(loggedInUser.pk);
|
105 | const myPostsFirstPage = await userFeed.items();
|
106 | // All the feeds are auto-paginated, so you just need to call .items() sequentially to get next page
|
107 | const myPostsSecondPage = await userFeed.items();
|
108 | await ig.media.like({
|
109 | // Like our first post from first page or first post from second page randomly
|
110 | mediaId: sample([myPostsFirstPage[0].id, myPostsSecondPage[0].id]),
|
111 | moduleInfo: {
|
112 | module_name: 'profile',
|
113 | user_id: loggedInUser.pk,
|
114 | username: loggedInUser.username,
|
115 | },
|
116 | d: sample([0, 1]),
|
117 | });
|
118 | })();
|
119 | ```
|
120 |
|
121 | # Basic concepts
|
122 |
|
123 | **You can find documentation in the [`docs` folder](docs)**.
|
124 | Consider starting in [`IgApiClient` (`index` module)](docs/classes/index/IgApiClient.md), the root class.
|
125 |
|
126 | You'll often see `ig` in the docs.
|
127 | This just refers to the client, an instance of [`IgApiClient`](docs/classes/index/IgApiClient.md) holding the state for one user.
|
128 |
|
129 | ```typescript
|
130 | import { IgApiClient } from 'instagram-private-api';
|
131 |
|
132 | // This is the general convention on how to name the client
|
133 | // vv
|
134 | const ig = new IgApiClient();
|
135 |
|
136 | // login, load a session etc.
|
137 | ```
|
138 |
|
139 | ## Repositories
|
140 |
|
141 | Repositories implement low-level operations - every method sends exactly _one_ api-request.
|
142 |
|
143 | - See the list of **available repositories** [here](docs/modules/repositories.md).
|
144 | - See the list of **their keys** in [`IgApiClient` here](docs/classes/index/IgApiClient.md).
|
145 |
|
146 | You access repositories on the [client (`IgApiClient`)](docs/classes/index/IgApiClient.md) by their lower-case (_camelCase_) name without the `Repository` suffix.
|
147 | For example, you access the instance of [`AddressBookRepository`](docs/classes/repositories/AddressBookRepository.md) by [`ig.addressBook`](docs/classes/index/IgApiClient.md#addressbook).
|
148 |
|
149 | ## Feeds
|
150 |
|
151 | Feeds represent paginated endpoints like a user's feed ([`UserFeed`](docs/classes/index/FeedFactory.md#user)).
|
152 | Think of feeds like (async-)iterators/streams/observables (in fact feeds are [async iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) and observable (`feed.item$`)).
|
153 | Every feed is accessible via `ig.feed.feedName()` (_camelCase_ name). `ig.feed` is the [`FeedFactory`](docs/classes/index/FeedFactory.md) that creates feeds for you connected to the instance of `ig`.
|
154 |
|
155 | - See the list of **available feeds** [here](docs/modules/feeds.md).
|
156 | - See the list of **their keys** in [`FeedFactory` (`ig.feed`) here](docs/classes/index/FeedFactory.md).
|
157 | - See [this example](examples/account-followers.feed.example.ts) and learn how to work with library feeds.
|
158 |
|
159 | Most of the feeds require initialization parameter(s), like a user-pk (id).
|
160 |
|
161 | ## Services
|
162 |
|
163 | 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.
|
164 |
|
165 | - See the list of **available repositories** [here](docs/modules/services.md).
|
166 | - See the list of **their keys** in [`IgApiClient` here](docs/classes/index/IgApiClient.md).
|
167 |
|
168 | # Debugging
|
169 |
|
170 | In order to get debug infos provided by the library, you can enable debugging.
|
171 | The prefix for this library is `ig`.
|
172 | To get all debug logs (_recommended_) set the namespace to `ig:*`.
|
173 |
|
174 | #### Node
|
175 |
|
176 | In Node you only have to set the environment variable `DEBUG` to the desired namespace.
|
177 | [Further information](https://github.com/visionmedia/debug#environment-variables)
|
178 |
|
179 | # Contribution
|
180 |
|
181 | If you need features that is not implemented - feel free to implement and create PRs!
|
182 |
|
183 | Plus we need some documentation, so if you are good in it - you are welcome.
|
184 |
|
185 | Setting up your environment is described [here](CONTRIBUTING.md).
|
186 |
|
187 | # Useful links
|
188 |
|
189 | [instagram-id-to-url-segment](https://www.npmjs.com/package/instagram-id-to-url-segment) - convert the image url fragment to the media ID
|
190 |
|
191 | ## Special thanks
|
192 |
|
193 | - [Richard Hutta](https://github.com/huttarichard), original author of this library. Thanks to him for starting it.
|
194 |
|
195 | ## Thanks to contributors
|
196 |
|
197 | - [Nerixyz](https://github.com/Nerixyz), for writing a huge amount of code for this library.
|