-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_lookup.js
51 lines (44 loc) · 1.15 KB
/
user_lookup.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
const needle = require("needle");
require("dotenv").config();
let userId = 77529292;
const bearerToken = process.env.BEARER_TOKEN;
console.log("token " + bearerToken);
const options = {
headers: {
"User-Agent": "v2FollowingJS",
Authorization: `Bearer ${bearerToken}`,
},
};
async function get_userinfo(userId) {
const url = `https://api.twitter.com/2/users/${userId}`;
let resp = {};
try {
resp = await needle("get", url, null, options);
//console.log("status code " + resp.statusCode);
//console.log("response body " + JSON.stringify(resp.body));
if (resp.statusCode != 200) {
console.log(
`${url} ${resp.statusCode} ${resp.headers} ${resp.statusMessage}:\n${resp.body}`
);
return;
}
} catch (e) {
console.log(e);
}
//console.log("get_userinfo " + JSON.stringify(resp.body.data));
return resp.body.data;
}
async function userInfo(userId) {
if (userId) {
let user = await get_userinfo(userId);
console.log(`user : ${user.name} `);
return user.name;
} else {
console.log("null user id");
return "noname";
}
}
//userInfo();
module.exports = {
userInfo: userInfo,
};