forked from kevva/instagram-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (30 loc) · 904 Bytes
/
index.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
'use strict';
const getEmails = require('get-emails');
const got = require('got');
module.exports = async username => {
if (typeof username !== 'string') {
throw new TypeError(`Expected \`username\` to be of type \`string\` but received type \`${typeof username}\``);
}
try {
const url = `https://instagram.com/${username}`;
const {graphql: {user}} = await got(url, {searchParams: {__a: 1}}).json();
const email = getEmails(user.biography).values().next().value || '';
return {
...user,
description: user.biography,
email,
followers: user.edge_followed_by.count,
following: user.edge_follow.count,
fullName: user.full_name,
posts: user.edge_owner_to_timeline_media.count,
url,
username,
website: user.external_url
};
} catch (error) {
if (error.response.statusCode === 404) {
error.message = `User "${username}" not found`;
}
throw error;
}
};