This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
52 lines (45 loc) · 1.75 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Hit FullContact v3 Enrich API with twitter
* names and get more social info back
*/
// Reqs & Configs
require('dotenv').config() // helps to have when running local
const axios = require('axios') // https://www.npmjs.com/package/axios
const fullcontactKey = process.env.FCKEY // get key from https://dashboard.fullcontact.com
// USER: add comma sep twitter handles with or without the @ symbol
const twitterHandlesToGrep = '@chuckreynolds'
// split up the names in that string to use each
const twitterHandleArray = twitterHandlesToGrep.split(',')
// Function to introduce a delay inside forEach loops cause we need that to not hammer FC
const delayLoop = (fn, delay) => {
return (x, i) => {
setTimeout(() => {
fn(x);
}, i * delay);
}
};
// let's loop through this bitch w/ delay added
twitterHandleArray.forEach(delayLoop(function (twitterHandle) {
// FC requires POST in v3 so Axios works better with these out here as objs
let axiosData = {
twitter: twitterHandle
}
let axiosConfig = {
headers: {
'Authorization': `Bearer ${fullcontactKey}`
}
}
// Post our payload and see what we get back
axios
.post('https://api.fullcontact.com/v3/person.enrich', axiosData, axiosConfig)
.then(response => {
console.log(`${twitterHandle},${response.data.fullName},${response.data.twitter},${response.data.linkedin},${response.data.facebook}`)
})
.catch(function (error) {
if (error.response.status == 404) {
console.log(`${twitterHandle},null,null,null,null`)
} else {
console.log(`${error.response.status} - ${error.response.statusText}`)
}
})
}, 1200)) // end forEach