-
Notifications
You must be signed in to change notification settings - Fork 0
/
instagram.js
44 lines (44 loc) · 1.61 KB
/
instagram.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const fetch = require("node-fetch");
module.exports = {
fetchUser: async function (user) {
let url = `https://www.instagram.com/${user}/?__a=1`;
let results = await fetch(url);
if (results.status !== 200) return false;
results = await results.json();
let data = {
username: results.graphql.user.username,
name: results.graphql.user.full_name,
bio: results.graphql.user.biography,
followers: results.graphql.user.edge_followed_by.count,
following: results.graphql.user.edge_follow.count,
profilePic: results.graphql.user.profile_pic_url_hd,
bioUrl: results.graphql.user.external_url,
id: results.graphql.user.id,
isPrivate: results.graphql.user.is_private,
posts: results.graphql.user.edge_owner_to_timeline_media.count,
};
return data;
},
/**
*
* @param {*} postId Put id after p/
* @example https://www.instagram.com/p/CRtrth5oJTV/
*/
fetchPost: async function (postId) {
let url = `https://www.instagram.com/p/${postId}/?__a=1`;
let results = await fetch(url);
if (results.status !== 200) return false;
results = await results.json();
let data = {
postPicture: results.graphql.shortcode_media.display_url,
createdBy: results.graphql.shortcode_media.owner.username,
caption:
results.graphql.shortcode_media.edge_media_to_caption.edges[0].node
.text,
totalCommants:
results.graphql.shortcode_media.edge_media_to_parent_comment.count,
location: results.graphql.shortcode_media.location,
};
return data;
},
};