forked from iamstarkov/get-twitter-followers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (25 loc) · 1.14 KB
/
index.js
File metadata and controls
29 lines (25 loc) · 1.14 KB
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
import Twitter from 'twit';
import { merge, flatten, concat, splitEvery, join, map, pipe } from 'ramda';
function usersLookupPromise(client, ids) {
const options = { user_id: join(',', ids), include_entities: false };
return client.post('users/lookup', options).then(({ data }) => data);
}
function ids2userObjects(client, ids) {
const userLookupPromises = pipe(splitEvery(100), map(usersLookupPromise.bind(null, client)));
const handler = (...userObjects) => flatten(userObjects);
return Promise.all(userLookupPromises(ids)).then(handler);
}
function accumulate(client, options, FriendsIds) {
return client.get('friends/ids', options).then(({ data: { ids, next_cursor_str: cursor } }) => {
const accumulatedFriendsIds = concat(FriendsIds, ids);
if (cursor === '0') {
return ids2userObjects(client, accumulatedFriendsIds);
}
return accumulate(client, merge(options, { cursor }), accumulatedFriendsIds);
});
}
export default function getTwitterFriends(tokens, username) {
const client = new Twitter(tokens);
const options = { screen_name: username, stringify_ids: true, count: 5000 };
return accumulate(client, options, []);
}