UNPKG

13 kBMarkdownView Raw
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
14Me and [Nerix](https://github.com/Nerixyz) are ready to announce the next 2.x.x version of this library.
15It has extended feature list.
16It's a big release.
17We have significantly expanded the functionality and capabilities.
18The library turned into a monorepository and now it's a set of libraries, connected in an ecosystem.
19It consists of
20
21- Android API
22- Web API
23- FBNS, Realtime
24
25We've done some work on design decisions.
26We simplified the state management process.
27Now 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.
28With new realtime features you can listen for new direct messages, notifications and any other events.
29
30The new version is hosted in private repository. Access is paid.
31Members get **basic** support for installation, configuration, and usage.
32We also will try to react on your feature requests.
33
34You can contact me in [telegram](https://t.me/bowzee) or [email](mailto:dilame.bowzee@gmail.com) for details.
35
36# Table of Contents
37
38- [Install](#install)
39- [Support us](#support-us)
40- [Examples](#examples)
41- [Basic Concepts](#basic-concepts)
42 - [Feeds](#feeds)
43 - [Repositories](#repositories)
44 - [Services](#services)
45- [Contribution](#contribution)
46- [Useful Links](#useful-links)
47 - [Special Thanks](#special-thanks)
48 - [Thanks to Contributors](#thanks-to-contributors)
49 - [End User License Agreement (EULA)](#end-user-license-agreement-eula)
50
51# Install
52
53From npm
54
55```
56npm install instagram-private-api
57```
58
59From github
60
61```
62npm install github:dilame/instagram-private-api
63```
64
65# Support us
66
67If you find this library useful for you, you can support it by donating any amount
68
69BTC: 1Dqnz9QuswAvD3t7Jsw7LhwprR6HAWprW6
70
71# Examples
72
73You can find usage examples [here](examples)
74
75_Note for JavaScript users:_
76As of Node v.13.5.0, there isn't support for ESModules and the 'import'-syntax.
77So you have to read the imports in the examples like this:
78
79`import { A } from 'b'``const { A } = require('b')`
80
81```typescript
82import { IgApiClient } from './index';
83import { sample } from 'lodash';
84const ig = new IgApiClient();
85// You must generate device id's before login.
86// Id's generated based on seed
87// So if you pass the same value as first argument - the same id's are generated every time
88ig.state.generateDevice(process.env.IG_USERNAME);
89// Optionally you can setup proxy url
90ig.state.proxyUrl = process.env.IG_PROXY;
91(async () => {
92 // Execute all requests prior to authorization in the real Android application
93 // Not required but recommended
94 await ig.simulate.preLoginFlow();
95 const loggedInUser = await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);
96 // The same as preLoginFlow()
97 // Optionally wrap it to process.nextTick so we dont need to wait ending of this bunch of requests
98 process.nextTick(async () => await ig.simulate.postLoginFlow());
99 // Create UserFeed instance to get loggedInUser's posts
100 const userFeed = ig.feed.user(loggedInUser.pk);
101 const myPostsFirstPage = await userFeed.items();
102 // All the feeds are auto-paginated, so you just need to call .items() sequentially to get next page
103 const myPostsSecondPage = await userFeed.items();
104 await ig.media.like({
105 // Like our first post from first page or first post from second page randomly
106 mediaId: sample([myPostsFirstPage[0].id, myPostsSecondPage[0].id]),
107 moduleInfo: {
108 module_name: 'profile',
109 user_id: loggedInUser.pk,
110 username: loggedInUser.username,
111 },
112 d: sample([0, 1]),
113 });
114})();
115```
116
117# Basic concepts
118
119## Feeds
120
121Feed allows you to get data. Every feed is accessible via `ig.feed.feedName`. See [nice example](https://github.com/dilame/instagram-private-api/blob/master/examples/account-followers.feed.example.ts) and learn how to work with library feeds.
122
123Available feeds key list:
124
125`accountFollowers`, `accountFollowing`, `news`, `discover`, `pendingFriendships`, `blockedUsers`, `directInbox`, `directPending`, `directThread`, `user`, `tag`, `location`, `mediaComments`, `reelsMedia`, `reelsTray`, `timeline`, `musicTrending`, `musicSearch`, `musicGenre`, `musicMood`, `usertags`, `saved`
126
127Most of the feeds requires initialization parameter, like user pk. Check [autogenerated docs](https://github.com/dilame/instagram-private-api/tree/master/docs), every feed doc link starts with `feeds/` and contains constructor with argument if needed.
128
129## Repositories
130
131Repositories 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.
132
133Keys is a little hints, with it you will be able to get access to repository via `ig.key`.
134
135| Key | Repository class documentation |
136| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
137| `account` | [AccountRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_account_repository_.accountrepository.md) |
138| `attribution` | [AttributionRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_attribution_repository_.attributionrepository.md) |
139| `challenge` | [ChallengeRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_challenge_repository_.challengerepository.md) |
140| `consent` | [ConsentRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_consent_repository_.consentrepository.md) |
141| `creatives` | [CreativesRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_creatives_repository_.creativesrepository.md) |
142| `direct` | [DirectRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_direct_repository_.directrepository.md) |
143| `directThread` | [DirectThreadRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_direct_thread_repository_.directthreadrepository.md) |
144| `discover` | [DiscoverRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_discover_repository_.discoverrepository.md) |
145| `fbsearch` | [FbsearchRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_fbsearch_repository_.fbsearchrepository.md) |
146| `friendship` | [FriendshipRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_friendship_repository_.friendshiprepository.md) |
147| `launcher` | [LauncherRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_launcher_repository_.launcherrepository.md) |
148| `linkedAccount` | [LinkedAccountRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_linked_account_repository_.linkedaccountrepository.md) |
149| `live` | [LiveRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_live_repository_.liverepository.md) |
150| `location` | [LocationRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_location_repository_.locationrepository.md) |
151| `locationSearch` | [LocationSearch](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_location_search_repository_.locationsearch.md) |
152| `loom` | [LoomRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_loom_repository_.loomrepository.md) |
153| `media` | [MediaRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_media_repository_.mediarepository.md) |
154| `music` | [MusicRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_music_repository_.musicrepository.md) |
155| `news` | [NewsRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_news_repository_.newsrepository.md) |
156| `qe` | [QeRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_qe_repository_.qerepository.md) |
157| `qp` | [QpRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_qp_repository_.qprepository.md) |
158| `tag` | [TagRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_tag_repository_.tagrepository.md) |
159| `upload` | [UploadRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_upload_repository_.uploadrepository.md) |
160| `user` | [UserRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_user_repository_.userrepository.md) |
161| `zr` | [ZrRepository](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_repositories_zr_repository_.zrrepository.md) |
162
163## Services
164
165Services 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.
166
167| Key | Service class documentation |
168| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
169| `publish` | [PublishService](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_services_publish_service_.publishservice.md) |
170| `search` | [SearchService](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_services_search_service_.searchservice.md) |
171| `simulate` | [SimulateService](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_services_simulate_service_.simulateservice.md) |
172| `story` | [StoryService](https://github.com/dilame/instagram-private-api/blob/master/docs/classes/_services_story_service_.storyservice.md) |
173
174# Debugging
175
176In order to get debug infos provided by the library, you can enable debugging.
177The prefix for this library is `ig`.
178To get all debug logs (_recommended_) set the namespace to `ig:*`.
179
180#### Node
181
182In node you only have to set the environment variable `DEBUG` to the desired namespace.
183[Further information](https://github.com/visionmedia/debug#environment-variables)
184
185#### Browser
186
187In the browser you have to set `localStorage.debug` to the desired namespace.
188[Further information](https://github.com/visionmedia/debug#browser-support)
189
190# Contribution
191
192If you need features that is not implemented - feel free to implement and create PRs!
193
194Plus we need some documentation, so if you are good in it - you are welcome.
195
196Setting up your environment is described [here](CONTRIBUTING.md).
197
198# Useful links
199
200[instagram-id-to-url-segment](https://www.npmjs.com/package/instagram-id-to-url-segment) - convert the image url fragment to the media ID
201
202## Special thanks
203
204- [Richard Hutta](https://github.com/huttarichard), original author of this library. Thanks to him for starting it.
205
206## Thanks to contributors
207
208- [Nerixyz](https://github.com/Nerixyz), for writing a huge amount of code for this library.