diff options
Diffstat (limited to 'includes/external/addressbook/twitter.js')
-rw-r--r-- | includes/external/addressbook/twitter.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/includes/external/addressbook/twitter.js b/includes/external/addressbook/twitter.js new file mode 100644 index 0000000..b22fca3 --- /dev/null +++ b/includes/external/addressbook/twitter.js @@ -0,0 +1,62 @@ +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']}`, + 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", + copy: [] + }, null, 2)); + } + + +})();
\ No newline at end of file |