Skip to content

Commit be6869c

Browse files
committed
Add method for get user media
1 parent 0dd8cd9 commit be6869c

File tree

3 files changed

+99
-38
lines changed

3 files changed

+99
-38
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ Inst.follow(3, 1) //unfollow "kevin"
6464
})
6565
})
6666
````
67+
68+
### Get user media
69+
````js
70+
//... auth (look up)
71+
//for example: get 12 first media entries for "kevin"
72+
// 0 - if you need to get first page
73+
// next cursor : r.page_info.end_cursor
74+
Insta.getUserMedia(3, '0', 12).then(f => console.log(f))
75+
````
76+
6777
When you pass items counter param instagram create pagination tokens on all iterations and gives on every response end_cursor, which the need to pass on next feed request
6878

6979

instagram.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const fetch = require('node-fetch');
99
const formData = require('form-data');
1010

1111
module.exports = class Instagram
12-
// class Instagram
1312
{
1413
/**
1514
* Constructor
@@ -401,4 +400,56 @@ module.exports = class Instagram
401400
{
402401
return this.getMediaInfoByUrl(url).then(t => t.media_id.split('_')[0])
403402
}
403+
404+
/**
405+
* Get media user list on userId with pagination
406+
* @param {String} userId
407+
* @param {String} cursor (next cursor). Use 0, if you want to get first page
408+
* @param {Int} mediaCounter default - 12
409+
* @return {Object} Promise
410+
*/
411+
getUserMedia(userId, cursor, mediaCounter)
412+
{
413+
mediaCounter = mediaCounter ? mediaCounter : 12
414+
let form = new formData()
415+
form.append('q', 'ig_user('+userId+') { media.after('+cursor+', '+mediaCounter+') {\
416+
count,\
417+
nodes {\
418+
__typename,\
419+
caption,\
420+
code,\
421+
comments {\
422+
count\
423+
},\
424+
comments_disabled,\
425+
date,\
426+
dimensions {\
427+
height,\
428+
width\
429+
},\
430+
display_src,\
431+
id,\
432+
is_video,\
433+
likes {\
434+
count\
435+
},\
436+
owner {\
437+
id\
438+
},\
439+
thumbnail_src,\
440+
video_views\
441+
},\
442+
page_info\
443+
}\
444+
}')
445+
form.append('ref', 'users::show')
446+
form.append('query_id', '17849115430193904') // this is static id. May be changed after rebuild, but now actually
447+
448+
return fetch('https://www.instagram.com/query/',
449+
{
450+
headers : this.getHeaders(),
451+
method : 'post',
452+
body : form
453+
}).then(r => r.text().then(t => t))
454+
}
404455
}

package.json

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
{
2-
"dependencies": {
3-
"fetch-cookie": "^0.6.0",
4-
"form-data": "^2.1.2",
5-
"node-fetch": "^1.6.3"
6-
},
7-
"name": "instagram-nodejs-without-api",
8-
"description": "Auth and get followers on instagram with nodejs",
9-
"version": "0.2.0",
10-
"main": "instagram.js",
11-
"scripts": {
12-
"test": "echo \"Error: no test specified\" && exit 1"
13-
},
14-
"repository": {
15-
"type": "git",
16-
"url": "git+https://github.com/yatsenkolesh/instagram-nodejs.git"
17-
},
18-
"keywords": [
19-
"Instagram",
20-
"Instagram",
21-
"without",
22-
"API",
23-
"get",
24-
"instagram",
25-
"followers",
26-
"nodejs",
27-
"mass-following",
28-
"mass-liking",
29-
"instagram-feed"
30-
],
31-
"author": "Alex Yatsenko <webfay1@gmail.com> (http://webfay.net)",
32-
"license": "BSD-3-Clause",
33-
"bugs": {
34-
"url": "https://github.com/yatsenkolesh/instagram-nodejs/issues"
35-
},
36-
"homepage": "https://github.com/yatsenkolesh/instagram-nodejs#readme"
37-
}
1+
{
2+
"dependencies": {
3+
"fetch-cookie": "^0.6.0",
4+
"form-data": "^2.1.2",
5+
"node-fetch": "^1.6.3"
6+
},
7+
"name": "instagram-nodejs-without-api",
8+
"description": "Auth and get followers on instagram with nodejs",
9+
"version": "0.2.5",
10+
"main": "instagram.js",
11+
"scripts": {
12+
"test": "echo \"Error: no test specified\" && exit 1"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/yatsenkolesh/instagram-nodejs.git"
17+
},
18+
"keywords": [
19+
"Instagram",
20+
"Instagram",
21+
"without",
22+
"API",
23+
"get",
24+
"instagram",
25+
"followers",
26+
"nodejs",
27+
"mass-following",
28+
"mass-liking",
29+
"instagram-feed"
30+
],
31+
"author": "Alex Yatsenko <webfay1@gmail.com> (http://webfay.net)",
32+
"license": "BSD-3-Clause",
33+
"bugs": {
34+
"url": "https://github.com/yatsenkolesh/instagram-nodejs/issues"
35+
},
36+
"homepage": "https://github.com/yatsenkolesh/instagram-nodejs#readme"
37+
}

0 commit comments

Comments
 (0)