const axios = require('axios'); const apiVersion = "2"; const app = require('../../app.json'); function sleep(ms) { return new Promise((res) => { setTimeout(res, ms); }); } (async () => { let user = process.argv[2]; try { let data = (await axios.get(`https://api.twitter.com/${apiVersion}/users/${user}?user.fields=id,description,profile_image_url`, { headers: { Authorization: `Bearer ${app.twitter.bearer}` } })).data.data; let obj = { error: null, avatar: "https://img.icons8.com/fluency-systems-regular/64/ffffff/twitter.png", name: data['name'], description: `@${data['username']}`, link: `https://twitter.com/${data['username']}`, copy: [ { title: "Copy link to profile", text: `https://twitter.com/${data['username']}` }, { title: "Copy username", text: `@${data['username']}` }, { title: "Copy ID", text: `${data['id']}` }, data['profile_image_url'] ? { title: "Copy avatar URL", text: data['profile_image_url'] } : null ] } if (data['profile_image_url']) { obj.avatar = data['profile_image_url']; } console.log(JSON.stringify(obj, null, 2)); } catch (e) { console.log(JSON.stringify({ error: e, avatar: "https://img.icons8.com/fluency-systems-regular/64/ffffff/twitter.png", name: user, description: "Twitter", link: null, copy: [] }, null, 2)); } })();