insta-api-wrapper 1.1.0 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,704 +1,126 @@
1
1
  # [insta-api-wrapper: Node.js](https://github.com/appit-online/insta-api-wrapper)
2
2
 
3
- A lightweight library to **fetch Instagram Stories, Reels, Highlights, user details, profiles, posts...**, including login and cookie handling .
3
+ A lightweight library to **fetch Instagram Stories, Reels, Highlights, user details, profiles, posts...**, including login and cookie handling — built for **Node.js** with `got` HTTP client.
4
4
 
5
5
  ---
6
6
 
7
- ## 🚀 Features
8
-
9
- - 🔐 Login and fetch session cookie or auth token via `getCookie` or `login` / `login2FA`
10
- - 🍪 Save & reuse sessions
11
- - 📖 `InstaService.getStories` – Fetch Instagram stories
12
- - 📦 `InstaService.fetchTrayStories` – Fetch all stories in the user's tray
13
- - 🌟 `InstaService.getHighlights` – Fetch Instagram highlights for a user
14
- - 👤 `InstaService.getUIdByUsername` – Get the user ID by username
15
- - 📝 `InstaService.getUserDetails` – Fetch detailed user information
16
- - 📷 `InstaService.fetchUserProfilePosts` – Fetch posts from a user's profile
17
- - 🖼️ `InstaService.fetchUserPostsByUserId` – Fetch posts by user ID
18
- - 🔗 `InstaService.fetchContentByUrl` – Fetch content from a post URL
19
- - ✂️ `InstaService.fetchContentByShortCode` – Fetch content using Instagram shortcode
20
- - 🆔 `InstaService.fetchContentByMediaId` – Fetch content by media ID
21
- - ➕ `InstaService.follow` – Follow a user by username or user ID
22
- - ❤️ `InstaService.like` – Like a post by media ID
7
+ ## Features
8
+
9
+ - Login via **Instagram Bloks CAA** protocol directly from the caller's IP (no server proxy)
10
+ - Full **2FA support** — TOTP, SMS, and airwave (push notification) accounts
11
+ - Follow and Like via Instagram Private API
12
+ - Fetch Stories, Highlights, Tray, User Profiles, Posts by URL/shortcode/mediaId
13
+ - Session persistence via `node-localstorage`
14
+ - Optional device parameter override via `setDeviceParams()` for consistent headers
15
+
23
16
  ---
24
17
 
25
18
  **Table of contents:**
26
19
 
27
- * [Quickstart](#quickstart)
28
-
29
- * [Installing the library](#installation)
30
- * [Using the library](#using-the-library)
20
+ * [Installation](#installation)
21
+ * [Login](#login)
22
+ * [API Usage](#api-usage)
31
23
  * [License](#license)
32
24
 
33
- ## Quickstart
34
-
35
-
36
- ## 📦 Installation
25
+ ## Installation
37
26
 
38
27
  ```bash
39
- npm install insta-api-wrapper --save
28
+ npm install insta-api-wrapper
40
29
  ```
41
30
 
42
- ### Using the library
43
-
44
- ### Cookie-based Authentication - Beta
45
- ```javascript
46
- import * as instaStory from 'insta-api-wrapper';
31
+ ## Login
47
32
 
48
- const username = 'your_instagram_username';
49
- const password = 'your_instagram_password';
33
+ ```typescript
34
+ import { LoginService } from 'insta-api-wrapper';
50
35
 
51
- // 🔐 Get Instagram session cookie (with optional force refetch)
52
- const refetchCookie = true;
53
- const userDetails = await instaStory.getCookie(username, password, refetchCookie);
36
+ const loginService = new LoginService({
37
+ backendUrl: 'https://your-backend.example.com' // optional — for device params & verify
38
+ });
54
39
 
55
- // 💾 Save cookie & expiration for reuse
56
- localStorage.setItem('cookie', userDetails.cookie);
57
- localStorage.setItem('expires', userDetails.expires);
40
+ const result = await loginService.login(username, password);
58
41
 
59
- // 📲 Initialize InstaService with your session cookie
60
- const igService = new instaStory.InstaService(userDetails.cookie);
42
+ if (result.twoFactorRequired) {
43
+ // Prompt for code, then:
44
+ const verified = await loginService.login2FA(password, code, '', username);
45
+ }
61
46
  ```
62
47
 
63
- ### Token Authentication
64
- ```javascript
65
- import * as instaStory from 'insta-api-wrapper';
66
-
67
- const username = 'your_instagram_username';
68
- const password = 'your_instagram_password';
48
+ All Instagram traffic goes directly from the caller — the backend is never used as a login proxy. To sync device parameters with your backend, call `loginService.setDeviceParams(...)` before login.
69
49
 
70
- // 🔐 Get Instagram auth token
71
- let userDetails: any;
72
- let loginService = new instaStory.LoginService();
73
- const reqHeaders = {
74
- 'User-Agent': 'Instagram 177.0.0.30.119 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)',
75
- }
76
-
77
- try {
78
- userDetails = await loginService.login(username, password, reqHeaders);
79
- }catch(e: any) {
80
- const parsed = JSON.parse(e);
81
- if (parsed.two_factor_required) {
82
- // 2FA required
83
- const info = parsed.two_factor_info;
84
- userDetails = await loginService.login2FA(password, twoFactorAppCode, twoFactorIdentifier, username, reqHeaders);
85
- }
86
- }
50
+ ## API Usage
87
51
 
88
- // 💾 Save userDetails for reuse
89
- /*
90
- import { LocalStorage } from "node-localstorage";
91
- const localStorage = new LocalStorage("./session");
92
- */
93
- localStorage.setItem('userDetails', userDetails);
52
+ ```typescript
53
+ import { InstaService } from 'insta-api-wrapper';
94
54
 
95
- // 📲 Initialize InstaService
96
- const igService = new instaStory.InstaService();
55
+ const igService = new InstaService();
97
56
  ```
98
57
 
99
- ```javascript
100
-
101
- /**
102
- * Get insta story tray
103
- * @param {string} request headers @optional - required for token authentication
104
- */
105
- // 📲 Initialize InstaService
106
- const igService = new instaStory.InstaService();
107
-
108
- const requestHeaders = {
109
- 'Authorization':userDetails.headers["ig-set-authorization"],
110
- "Ig-U-Ds-User-Id": userDetails.headers["ig-set-ig-u-ds-user-id"],
111
- "Ig-U-Rur": userDetails.headers["ig-set-ig-u-rur"],
112
- "X-Ig-Www-Claim": userDetails.headers["x-ig-set-www-claim"],
113
- 'User-Agent': 'Instagram 177.0.0.30.119 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)',
114
- }
58
+ All API methods accept an optional `headers` parameter for auth. The lib uses Android headers by default — you only need to pass the session-specific auth headers:
115
59
 
116
- // 📖 Fetch Instagram Tray Stories
117
- const storyTray = await igService.fetchTrayStories(requestHeaders);
118
- console.log(storyTray);
119
- [
120
- {
121
- "id": "21335",
122
- "full_name": "Yoga Instructor",
123
- "username": "mrstest",
124
- "story_duration_secs": 5,
125
- "media_count": 4,
126
- "has_video": true,
127
- "profile_pic_url": "https://scontent-muc2-1.cdninstagram.com/v/5770385_n.jpg",
128
- "is_verified": false,
129
- "is_private": false
130
- },
131
- ...
132
- ]
60
+ ```typescript
61
+ const authHeaders = {
62
+ 'Authorization': session.headers['ig-set-authorization'],
63
+ 'Ig-U-Ds-User-Id': session.headers['ig-set-ig-u-ds-user-id'],
64
+ 'Ig-U-Rur': session.headers['ig-set-ig-u-rur'],
65
+ 'X-Ig-Www-Claim': session.headers['x-ig-set-www-claim'],
66
+ };
133
67
  ```
134
68
 
135
- ```javascript
136
-
137
- /**
138
- * Get insta stories
139
- * @param {string} username value
140
- * @param {boolean} export insta response @optional - include raw GraphQL data
141
- * @param {string} request headers @optional - required for token authentication
142
- */
143
- // 📖 Fetch Instagram Stories
144
- try {
145
- const requestHeaders = {
146
- 'Authorization':userDetails.headers["ig-set-authorization"],
147
- "Ig-U-Ds-User-Id": userDetails.headers["ig-set-ig-u-ds-user-id"],
148
- "Ig-U-Rur": userDetails.headers["ig-set-ig-u-rur"],
149
- "X-Ig-Www-Claim": userDetails.headers["x-ig-set-www-claim"],
150
- 'User-Agent': 'Instagram 177.0.0.30.119 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)',
151
- }
152
-
153
- const stories = await igService.getStories('someuser', true, requestHeaders);
154
- console.log(stories);
155
- } catch (error: any) {
156
- if (error.message === 'private profile') {
157
- console.warn('The user profile is private and stories cannot be accessed.');
158
- } else {
159
- console.error('Unknown error:', error);
160
- }
161
- }
69
+ ### Stories
162
70
 
163
- {
164
- "id": "123008993",
165
- "username": "someusername",
166
- "name": "User Name",
167
- "profilePicture": "https://scontent-muc2-1.cdninstagram.com/v/t51.2885-19/403891526_89150552568277163_n.jpg",
168
- "stories_count": 10,
169
- "media": [
170
- {
171
- "id": "36999034226_191008993",
172
- "taken_at": 1755282929,
173
- "expiring_at": 1755369329,
174
- "original_width": 640,
175
- "original_height": 1136,
176
- "caption": null,
177
- "thumbnail": "https://scontent-muc2-1.cdninstagram.com/v/t51.2885-15/533658976_73414557283417579416565_n.jpg",
178
- "thumbnailDefault": "https://scontent-muc2-1.cdninstagram.com/v/t51.2885-15/53365897678818856079416565_n.jpg",
179
- "type": "video",
180
- "mimetype": "video/mp4",
181
- "url": "https://scontent-muc2-1.cdninstagram.com/o1/v/t2/f2/m78/AQOcKHtdfCkfdfJ5XMY96xY4_IiwMQ7vvgM9U1Yo-lcutWgH9AfdDbofL1f8Y13r7g647Gk.mp4",
182
- "has_audio": true,
183
- "video_duration": 4.77
184
- },
185
- {
186
- "id": "369972572609_191008993",
187
- "taken_at": 1755261686,
188
- "expiring_at": 1755348086,
189
- "original_width": 1179,
190
- "original_height": 2096,
191
- "caption": null,
192
- "thumbnail": "https://scontent-muc2-1.cdninstagram.com/v/t51.2885-15/5331086517083875_n.jpg",
193
- "thumbnailDefault": "https://scontent-muc2-1.cdninstagram.com/v/t51.2885-15/533108886_701523226517083875_n.jpg",
194
- "type": "image",
195
- "mimetype": "image/jpeg",
196
- "url": "https://scontent-muc2-1.cdninstagram.com/v/t51.2885-15/533108886_18525701523226517083875_n.jpg",
197
- "has_audio": false,
198
- "video_duration": 0
199
- },
200
- ...
201
- ]
202
- }
71
+ ```typescript
72
+ const tray = await igService.fetchTrayStories(authHeaders);
73
+ const stories = await igService.getStories('someuser', true, authHeaders);
74
+ const highlights = await igService.getHighlights('someuser', authHeaders);
203
75
  ```
204
76
 
205
- ```javascript
206
-
207
- /**
208
- * Get profile highlights
209
- * @param {string} username value
210
- * @param {string} request headers @optional - required for token authentication
211
- */
212
- try {
213
- const reqHeaders = {}
214
- const stories = await igService.getHighlights('someuser', reqHeaders);
215
- console.log(stories);
216
- } catch (error: any) {
217
- console.error('Unknown error:', error);
218
- }
219
-
220
- {
221
- "last_paginated_highlights_node_edited_at_ts": null,
222
- "has_fetched_all_remaining_highlights": null,
223
- "suggested_highlights": {},
224
- "cursor": null,
225
- "highlights_tray_type": "DEFAULT",
226
- "my_week_enabled": null,
227
- "status": "ok",
228
- "tray": [
229
- {
230
- "id": "highlight:1234567890",
231
- "reel_type": "highlight_reel",
232
- "title": "Mein Highlight",
233
- "created_at": 1700000000,
234
- "is_pinned_highlight": false,
235
- "prefetch_count": 0,
236
- "disabled_reply_types": [
237
- "story_remix_reply",
238
- "story_selfie_reply"
239
- ],
240
- "highlight_reel_type": "DEFAULT",
241
- "is_converted_to_clips": false,
242
- "is_nux": false,
243
- "can_gif_quick_reply": true,
244
- "can_reshare": false,
245
- "is_archived": false,
246
- "strong_id__": "highlight:1234567890",
247
- "cover_media": {
248
- "crop_rect": [0.1, 0.1, 0.9, 0.9],
249
- "media_id": "9876543210_123456789",
250
- "upload_id": null,
251
- "cropped_image_version": {
252
- "height": 150,
253
- "scans_profile": "",
254
- "url": "https://example.com/cropped_image.jpg",
255
- "width": 150
256
- },
257
- "full_image_version": null
258
- },
259
- "ranked_position": -1000,
260
- "seen_ranked_position": -1000,
261
- "media_count": 10,
262
- "updated_timestamp": 1700001000,
263
- "latest_reel_media": 1700000500,
264
- "seen": null,
265
- "can_reply": true,
266
- "can_react_with_avatar": false,
267
- "contains_stitched_media_blocked_by_rm": false,
268
- "user": {
269
- "pk": "123456789",
270
- "full_name": "Max Mustermann",
271
- "pk_id": "123456789",
272
- "id": "123456789",
273
- "strong_id__": "123456789",
274
- "username": "max123",
275
- "is_private": false,
276
- "is_verified": false,
277
- "profile_pic_id": "1111111111_123456789",
278
- "profile_pic_url": "https://example.com/profile_pic.jpg",
279
- "account_badges": [],
280
- "interop_messaging_user_fbid": 999999999999,
281
- "is_creator_agent_enabled": false
282
- }
283
- }
284
- ]
285
- }
77
+ ### User Info
286
78
 
287
-
288
- ````
289
-
290
- ```javascript
291
- /**
292
- * Get insta userId
293
- * @param {string} username value
294
- * @param {string} request headers @optional
295
- */
296
- // 📖 Fetch Instagram UserId
297
- try {
298
- const reqHeaders = {}
299
- const uid = await igService.getUIdByUsername('someuser', reqHeaders);
300
- console.log(uid);
301
- } catch (error: any) {
302
- console.error('Unknown error:', error);
303
- }
304
-
305
-
306
- /**
307
- * Get insta profile
308
- * @param {string} username value
309
- * @param {string} request headers @optional
310
- */
311
- try {
312
- const reqHeaders = {}
313
- const profile = await igService.getUserDetails('someuser', reqHeaders);
314
- console.log(profile);
315
- } catch (error: any) {
316
- console.error('Unknown error:', error);
317
- }
318
-
319
- {
320
- "ai_agent_type": null,
321
- "biography": "Example biography with some emojis and mentions like @exampleuser.",
322
- "bio_links": [
323
- {
324
- "title": "",
325
- "lynx_url": "https://l.instagram.com/?u=http%3A%2F%2Fexample.com%2Fprofile&e=AT123456789",
326
- "url": "http://example.com/profile",
327
- "link_type": "external"
328
- }
329
- ],
330
- "fb_profile_biolink": null,
331
- "biography_with_entities": {
332
- "raw_text": "Example biography with @users and #hashtags",
333
- "entities": [
334
- {
335
- "user": {
336
- "username": "exampleuser"
337
- },
338
- "hashtag": null
339
- }
340
- ]
341
- },
342
- "blocked_by_viewer": false,
343
- "restricted_by_viewer": false,
344
- "country_block": false,
345
- "eimu_id": "1234567890",
346
- "external_url": "http://example.com",
347
- "external_url_linkshimmed": "https://l.instagram.com/?u=http%3A%2F%2Fexample.com&e=AT123456789",
348
- "edge_followed_by": {
349
- "count": 12345
350
- },
351
- "fbid": "17840000000000000",
352
- "followed_by_viewer": true,
353
- "edge_follow": {
354
- "count": 150
355
- },
356
- "follows_viewer": false,
357
- "full_name": "Example Name",
358
- "group_metadata": null,
359
- "has_ar_effects": false,
360
- "has_clips": true,
361
- "has_guides": false,
362
- "has_chaining": true,
363
- "has_channel": false,
364
- "has_blocked_viewer": false,
365
- "highlight_reel_count": 5,
366
- "has_requested_viewer": false,
367
- "hide_like_and_view_counts": false,
368
- "id": "123456789",
369
- "is_business_account": false,
370
- "is_professional_account": true,
371
- "is_supervision_enabled": false,
372
- "is_guardian_of_viewer": false,
373
- "is_supervised_by_viewer": false,
374
- "is_supervised_user": false,
375
- "is_embeds_disabled": false,
376
- "is_joined_recently": false,
377
- "guardian_id": null,
378
- "business_address_json": null,
379
- "business_contact_method": "UNKNOWN",
380
- "business_email": null,
381
- "business_phone_number": null,
382
- "business_category_name": null,
383
- "overall_category_name": null,
384
- "category_enum": null,
385
- "category_name": "Public Figure",
386
- "is_private": false,
387
- "is_verified": true,
388
- "is_verified_by_mv4b": false,
389
- "is_regulated_c18": false,
390
- "edge_mutual_followed_by": {
391
- "count": 0,
392
- "edges": []
393
- },
394
- "pinned_channels_list_count": 0,
395
- "profile_pic_url": "https://example.com/profile.jpg",
396
- "profile_pic_url_hd": "https://example.com/profile_hd.jpg",
397
- "requested_by_viewer": false,
398
- "should_show_category": true,
399
- "should_show_public_contacts": false,
400
- "show_account_transparency_details": true,
401
- "transparency_label": null,
402
- "transparency_product": null,
403
- "username": "exampleuser",
404
- "pronouns": [],
405
- "edge_owner_to_timeline_media": {
406
- "count": 100,
407
- "page_info": {
408
- "has_next_page": true,
409
- "end_cursor": ""
410
- },
411
- "edges": []
412
- }
413
- }
79
+ ```typescript
80
+ const uid = await igService.getUIdByUsername('someuser', authHeaders);
81
+ const profile = await igService.getUserDetails('someuser', authHeaders); // web/GraphQL
82
+ const profileV1 = await igService.getUserInfoV1('someuser', authHeaders); // V1 Private API (use with Bloks auth)
414
83
  ```
415
84
 
416
- ```javascript
417
- /**
418
- * Get insta posts from user profile
419
- * @param {string} username value
420
- * @param {string} maxId - pagination of user posts - use response attribute next_max_id for more posts
421
- * @param {string} request headers @optional
422
- */
423
- try {
424
- const reqHeaders = {}
425
- const profile = await igService.fetchUserProfilePosts('someuser', '', reqHeaders);
426
- console.log(profile);
427
- } catch (error: any) {
428
- console.error('Unknown error:', error);
429
- }
85
+ ### Posts
430
86
 
431
- try {
432
- const reqHeaders = {}
433
- const profile = await igService.fetchUserPostsByUserId('190008993', '', reqHeaders);
434
- console.log(profile);
435
- } catch (error: any) {
436
- console.error('Unknown error:', error);
437
- }
438
-
439
- {
440
- "id": "123455",
441
- "username": "username",
442
- "name": "User Name",
443
- "is_private": false,
444
- "is_verified": true,
445
- "profile_pic_url": "https://scontent-muc2-1.cdninstagram.com/v/t51.2885-19/403891521097167925951577163_n.jpg",
446
- "more_available": true,
447
- "next_max_id": "3696312669046_13753680437",
448
- "media": [
449
- {
450
- "like_and_view_counts_disabled": false,
451
- "has_privately_liked": false,
452
- "is_post_live_clips_media": false,
453
- "is_quiet_post": false,
454
- "taken_at": 1755342216,
455
- "has_tagged_users": false,
456
- "media_type": 2,
457
- "code": "DUMMYCODE123",
458
- "caption": {
459
- "text": "🔥 Beispieltext 🔥\n\nHier steht ein Dummy-Beitrag mit Hashtags und Emojis. 🏆\n\n#Beispiel #Dummy #Test"
460
- },
461
- "play_count": 12345,
462
- "has_views_fetching": true,
463
- "ig_play_count": 12345,
464
- "image_versions2": {
465
- "candidates": [
466
- {
467
- "height": 1920,
468
- "width": 1080,
469
- "url": "https://example.com/image_1080.jpg"
470
- },
471
- {
472
- "height": 1333,
473
- "width": 750,
474
- "url": "https://example.com/image_750.jpg"
475
- },
476
- {
477
- "height": 1137,
478
- "width": 640,
479
- "url": "https://example.com/image_640.jpg"
480
- },
481
- {
482
- "height": 853,
483
- "width": 480,
484
- "url": "https://example.com/image_480.jpg"
485
- },
486
- {
487
- "height": 568,
488
- "width": 320,
489
- "url": "https://example.com/image_320.jpg"
490
- }
491
- ]
492
- }
493
- },...
87
+ ```typescript
88
+ const posts = await igService.fetchUserProfilePosts('someuser', '', authHeaders);
89
+ const more = await igService.fetchUserProfilePosts('someuser', posts.next_max_id, authHeaders);
90
+ const post = await igService.fetchContentByUrl('https://www.instagram.com/p/ABC123/', authHeaders);
91
+ const post2 = await igService.fetchContentByShortCode('ABC123', authHeaders);
92
+ const post3 = await igService.fetchContentByMediaId('369174122649_457051784', authHeaders);
494
93
  ```
495
94
 
496
- ```javascript
497
-
498
- /**
499
- * Get post, reel... by url
500
- * @param {string} url
501
- * @param {string} request headers @optional - required for token authentication
502
- */
503
- try {
504
- const requestHeaders = {
505
- 'Authorization':userDetails.headers["ig-set-authorization"],
506
- "Ig-U-Ds-User-Id": userDetails.headers["ig-set-ig-u-ds-user-id"],
507
- "Ig-U-Rur": userDetails.headers["ig-set-ig-u-rur"],
508
- "X-Ig-Www-Claim": userDetails.headers["x-ig-set-www-claim"],
509
- 'User-Agent': 'Instagram 177.0.0.30.119 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)',
510
- }
511
-
512
- const post = await igService.fetchContentByUrl('https://www.instagram.com/p/DM777IJO7rd/?igsh=MWM2ejl2Mm8zcWRtcg==', requestHeaders);
513
- console.log(post);
514
- } catch (error: any) {
515
- console.error('Unknown error:', error);
516
- }
517
-
518
- /**
519
- * Get post by shortCode
520
- * @param {string} shortCode
521
- * @param {string} request headers @optional - required for token authentication
522
- */
523
- try {
524
- const requestHeaders = {
525
- 'Authorization':userDetails.headers["ig-set-authorization"],
526
- "Ig-U-Ds-User-Id": userDetails.headers["ig-set-ig-u-ds-user-id"],
527
- "Ig-U-Rur": userDetails.headers["ig-set-ig-u-rur"],
528
- "X-Ig-Www-Claim": userDetails.headers["x-ig-set-www-claim"],
529
- 'User-Agent': 'Instagram 177.0.0.30.119 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)',
530
- }
531
-
532
- const post = await igService.fetchContentByShortCode('AU7s3IJO7rd', requestHeaders);
533
- console.log(post);
534
- } catch (error: any) {
535
- console.error('Unknown error:', error);
536
- }
95
+ ### Follow & Like
537
96
 
538
- {
539
- "username": "dummyuser",
540
- "name": "Max Mustermann",
541
- "postType": "p",
542
- "media_id": "123456789012345678_9876543210",
543
- "shortcode": "ABC123XYZ",
544
- "createdAt": 1700000000,
545
- "likes": 42,
546
- "caption": "Hier ist ein Dummy-Beitrag mit Bild. 🌟🥳 #dummy #testpost",
547
- "media_count": 1,
548
- "comment_count": 3,
549
- "video_duration": 0,
550
- "music": {},
551
- "media": [
552
- {
553
- "id": "123456789012345678_9876543210",
554
- "thumbnail": "https://via.placeholder.com/1080x1350.png?text=Thumbnail",
555
- "url": "https://via.placeholder.com/1080x1350.png?text=Full+Image",
556
- "type": "image",
557
- "dimensions": {
558
- "height": 1350,
559
- "width": 1080
560
- }
561
- }
562
- ]
563
- }
97
+ ```typescript
98
+ const followed = await igService.follow('usernameOrId', authHeaders);
99
+ const liked = await igService.like('shortCode', authHeaders);
564
100
  ```
565
101
 
102
+ ### Device Parameters
566
103
 
567
- ```javascript
568
- /**
569
- * Get post, highlight, reel by mediaId
570
- * @param {string} mediaId
571
- * @param {string} request headers @optional - required for token authentication
572
- */
573
- try {
574
- const requestHeaders = {
575
- 'Authorization':userDetails.headers["ig-set-authorization"],
576
- "Ig-U-Ds-User-Id": userDetails.headers["ig-set-ig-u-ds-user-id"],
577
- "Ig-U-Rur": userDetails.headers["ig-set-ig-u-rur"],
578
- "X-Ig-Www-Claim": userDetails.headers["x-ig-set-www-claim"],
579
- 'User-Agent': 'Instagram 177.0.0.30.119 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)',
580
- }
581
-
582
- const post = await igService.fetchContentByMediaId('3691741226493_45705178442', requestHeaders);
583
- console.log(post);
584
- } catch (error: any) {
585
- console.error('Unknown error:', error);
586
- }
104
+ The lib ships with hardcoded Android device defaults (Pixel 8 Pro, Instagram 428.0.0.47.67). To override:
587
105
 
588
- {
589
- "username": "username",
590
- "name": "Dummy Name",
591
- "postType": "story",
592
- "media_id": "369464054_458376602",
593
- "shortcode": "DNFoF7y",
594
- "createdAt": 1754155492,
595
- "media": [
596
- {
597
- "like_and_view_counts_disabled": false,
598
- "has_privately_liked": false,
599
- "is_post_live_clips_media": false,
600
- "is_quiet_post": false,
601
- "taken_at": 1754655492,
602
- "media_type": 2,
603
- "code": "DUMMY_CODE_123",
604
- "has_views_fetching": true,
605
- "image_versions2": {
606
- "candidates": [
607
- {
608
- "height": 1136,
609
- "width": 640,
610
- "url": "https://example.com/image1_1136x640.jpg"
611
- },
612
- {
613
- "height": 852,
614
- "width": 480,
615
- "url": "https://example.com/image2_852x480.jpg"
616
- },
617
- {
618
- "height": 568,
619
- "width": 320,
620
- "url": "https://example.com/image3_568x320.jpg"
621
- },
622
- {
623
- "height": 426,
624
- "width": 240,
625
- "url": "https://example.com/image4_426x240.jpg"
626
- },
627
- {
628
- "height": 640,
629
- "width": 640,
630
- "url": "https://example.com/image5_640x640.jpg"
631
- }
632
- ]
633
- }
634
- }
635
- ]
636
- }
106
+ ```typescript
107
+ loginService.setDeviceParams({ version: '428.0.0.47.67', bloksVersioningId: '...' });
637
108
  ```
638
109
 
110
+ Expected format (e.g. from a backend `/api/details` endpoint):
639
111
 
640
- ``` javascript
641
- /**
642
- * Follow Account
643
- * @param {string} username or userId
644
- * @param {string} request headers @optional - required for token authentication
645
- */
646
- try {
647
- const requestHeaders = {
648
- 'Authorization':userDetails.headers["ig-set-authorization"],
649
- "Ig-U-Ds-User-Id": userDetails.headers["ig-set-ig-u-ds-user-id"],
650
- "Ig-U-Rur": userDetails.headers["ig-set-ig-u-rur"],
651
- "X-Ig-Www-Claim": userDetails.headers["x-ig-set-www-claim"],
652
- "User-Agent": 'Instagram 177.0.0.30.119 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)',
653
- }
654
-
655
- const followed = await igService.follow('usernameOrId', requestHeaders);
656
- console.log(followed);
657
-
658
- } catch (error: any) {
659
- console.error('Unknown error:', error);
660
- }
661
-
662
- {
663
- "following": true,
664
- "is_bestie": false,
665
- "is_feed_favorite": false,
666
- "is_private": false,
667
- "is_restricted": false,
668
- "incoming_request": false,
669
- "outgoing_request": false,
670
- "followed_by": false,
671
- "muting": false,
672
- "blocking": false,
673
- "is_eligible_to_subscribe": false,
674
- "subscribed": false
675
- }
676
- ```
677
-
678
- ``` javascript
679
- /**
680
- * Like Post
681
- * @param {string} shortCode
682
- * @param {string} request headers @optional - required for token authentication
683
- */
684
- try {
685
- const requestHeaders = {
686
- 'Authorization':userDetails.headers["ig-set-authorization"],
687
- "Ig-U-Ds-User-Id": userDetails.headers["ig-set-ig-u-ds-user-id"],
688
- "Ig-U-Rur": userDetails.headers["ig-set-ig-u-rur"],
689
- "X-Ig-Www-Claim": userDetails.headers["x-ig-set-www-claim"],
690
- 'User-Agent': 'Instagram 177.0.0.30.119 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)',
691
- }
692
-
693
- const liked = await igService.like('shortCode', requestHeaders);
694
- console.log(liked);
695
-
696
- } catch (error: any) {
697
- console.error('Unknown error:', error);
698
- }
699
-
112
+ ```json
700
113
  {
701
- "status": "ok"
114
+ "version": "428.0.0.47.67",
115
+ "defaultCodeName": "husky",
116
+ "defaultManufacturer": "Google/google",
117
+ "defaultModel": "Pixel 8 Pro",
118
+ "defaultAndroidVersion": "34",
119
+ "defaultAndroidRelease": "14",
120
+ "defaultScreenDpi": "480dpi",
121
+ "defaultResolution": "1344x2992",
122
+ "defaultAppVersionCode": "961145276",
123
+ "bloksVersioningId": "7189b949425f9bf80ea8bd880cf5a3080b292d9b1c4b38a18d112f7c4b71e7a8"
702
124
  }
703
125
  ```
704
126
 
@@ -45,6 +45,9 @@ export declare class InstaService {
45
45
  getUserDetails(username: string, headers?: {
46
46
  [key: string]: string;
47
47
  }): Promise<UserGraphQlV2>;
48
+ getUserInfoV1(userId: string, headers?: {
49
+ [key: string]: string;
50
+ }): Promise<any>;
48
51
  /**
49
52
  * fetch profile by username. including email, phone number and posts
50
53
  * @param {username} username
@@ -92,6 +92,10 @@ export class InstaService {
92
92
  const graphql = res?.data;
93
93
  return graphql.data?.user;
94
94
  }
95
+ async getUserInfoV1(userId, headers = {}) {
96
+ const res = await this.fetchAPI(config.instagram_api_v1, `/users/${userId}/info/`, { headers, method: 'GET', params: { is_prefetch: 'false', entry_point: 'self_profile', from_module: 'self_profile' } });
97
+ return res?.data?.user ?? {};
98
+ }
95
99
  /**
96
100
  * fetch profile by username. including email, phone number and posts
97
101
  * @param {username} username
@@ -1,6 +1,8 @@
1
+ import { BloksDeviceParams } from './login.bloks.js';
1
2
  export interface LoginServiceConfig {
3
+ /** Base URL of the backend. Used only for verify (follow/like on login). No trailing slash. */
2
4
  backendUrl?: string;
3
- headersPath?: string;
5
+ /** Path to the verify endpoint. Defaults to /v2/insta/verify */
4
6
  verifyPath?: string;
5
7
  }
6
8
  export declare class LoginService {
@@ -9,12 +11,10 @@ export declare class LoginService {
9
11
  deviceId: string;
10
12
  private phoneId;
11
13
  private readonly backendUrl;
12
- private readonly headersPath;
13
14
  private readonly verifyPath;
14
15
  private readonly bloksSvc;
15
- private deviceParamsLoaded;
16
16
  constructor(cfg?: LoginServiceConfig);
17
- private loadDeviceParams;
17
+ setDeviceParams(p: BloksDeviceParams): void;
18
18
  login(username: string, pass: string, reqHeaders?: {
19
19
  [key: string]: string;
20
20
  }): Promise<any>;
@@ -7,30 +7,18 @@ const localStorage = new LocalStorage('./scratch');
7
7
  export class LoginService {
8
8
  constructor(cfg = {}) {
9
9
  this.cfg = cfg;
10
- this.deviceParamsLoaded = false;
11
10
  this.backendUrl = cfg.backendUrl ?? 'https://reelsaver.appit-online.de';
12
- this.headersPath = cfg.headersPath ?? '/api/details';
13
11
  this.verifyPath = cfg.verifyPath ?? '/v2/insta/verify';
14
12
  this.uuid = this.getOrCreate('insta_uuid', uuidv4);
15
13
  this.deviceId = this.generateDeviceId();
16
14
  this.phoneId = this.getOrCreate('insta_phone_id', uuidv4);
17
15
  this.bloksSvc = new BloksLoginService(this.uuid, this.phoneId, this.deviceId);
18
16
  }
19
- async loadDeviceParams() {
20
- if (this.deviceParamsLoaded)
21
- return;
22
- this.deviceParamsLoaded = true;
23
- try {
24
- const resp = await got.get(`${this.backendUrl}${this.headersPath}`, { responseType: 'json' });
25
- const p = resp.body;
26
- if (p?.bloksVersioningId || p?.version)
27
- this.bloksSvc.setDeviceParams(p);
28
- }
29
- catch (_) { }
17
+ setDeviceParams(p) {
18
+ this.bloksSvc.setDeviceParams(p);
30
19
  }
31
20
  // ─── Public login API ───────────────────────────────────────────────────────
32
21
  async login(username, pass, reqHeaders = {}) {
33
- await this.loadDeviceParams();
34
22
  const result = await this.bloksSvc.login(username, pass);
35
23
  if (result.twoFactorRequired)
36
24
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insta-api-wrapper",
3
- "version": "1.1.0",
3
+ "version": "1.1.4",
4
4
  "description": "Anonymous Stories, Search & Download reels, posts, highlights... on Insta",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",