Skip to content

Commit 072a32d

Browse files
committed
Profile Lookup
1 parent 7ca8a07 commit 072a32d

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

src/index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const PARAMS__RETURN_URL = 'return_url';
8181
const PARAMS__SCOPE = 'scope';
8282
const PARAMS__SEARCH_TYPE = 'search_type';
8383
const PARAMS__TEXT = 'text';
84+
const PARAMS__USERNAME = 'username';
8485

8586
// Read variables from environment
8687
require('dotenv').config();
@@ -118,6 +119,7 @@ const SCOPES = [
118119
'threads_manage_mentions',
119120
'threads_delete',
120121
'threads_location_tagging',
122+
'threads_profile_discovery',
121123
];
122124

123125
app.use(express.static('public'));
@@ -898,6 +900,56 @@ app.get('/oEmbed', async (req, res) => {
898900
});
899901
});
900902

903+
app.get('/profileLookup', async (req, res) => {
904+
const { profile } = req.query;
905+
if (!profile) {
906+
return res.render('profile_lookup', {
907+
title: 'Profile Lookup',
908+
});
909+
}
910+
911+
const params = {
912+
[PARAMS__USERNAME]: profile,
913+
}
914+
915+
const profileLookupUrl = buildGraphAPIURL(`profile_lookup`, params, req.session.access_token);
916+
917+
let response = {};
918+
try {
919+
response = await axios.get(profileLookupUrl, { httpsAgent: agent });
920+
} catch (e) {
921+
console.error(e?.response?.data?.error?.message ?? e.message);
922+
}
923+
924+
const username = response.data?.username;
925+
const displayName = response.data?.name;
926+
const profilePictureUrl = response.data?.profile_picture_url;
927+
const isVerified = response.data?.is_verified;
928+
const bio = response.data?.biography;
929+
const formatCount = count => count ? count.toLocaleString('en-US') : undefined;
930+
const followerCount = formatCount(response.data?.follower_count);
931+
const likesCount = formatCount(response.data?.likes_count);
932+
const quotesCount = formatCount(response.data?.quotes_count);
933+
const repliesCount = formatCount(response.data?.replies_count);
934+
const repostsCount = formatCount(response.data?.reposts_count);
935+
const viewsCount = formatCount(response.data?.views_count);
936+
937+
return res.render('profile_lookup', {
938+
title: 'Profile Lookup for @'.concat(profile),
939+
username,
940+
displayName,
941+
profilePictureUrl,
942+
isVerified,
943+
bio,
944+
followerCount,
945+
likesCount,
946+
quotesCount,
947+
repliesCount,
948+
repostsCount,
949+
viewsCount,
950+
});
951+
});
952+
901953
https
902954
.createServer({
903955
key: fs.readFileSync(path.join(__dirname, '../'+ HOST +'-key.pem')),

views/account.pug

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ block content
2020
button(onclick="location.href='/replies'") My Replies
2121
button(onclick="location.href='/mentions'") My Mentions
2222
button(onclick="location.href='/keywordSearch'") Search for Threads
23+
button(onclick="location.href='/profileLookup'") Profile Lookup
2324
button(onclick="location.href='/userInsights'") My Insights
2425
button(onclick="location.href='/publishingLimit'") Publishing Limit

views/profile_lookup.pug

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
extends layout
2+
3+
block content
4+
style(type="text/css").
5+
#example-accounts {
6+
margin: 0 auto;
7+
width: 100px;
8+
text-align: left;
9+
}
10+
form.profileLookup {
11+
margin-top: 50px;
12+
}
13+
14+
p Try looking up one of these profiles:
15+
ul#example-accounts
16+
li
17+
a(href='https://www.threads.net/@meta') @meta
18+
li
19+
a(href='https://www.threads.net/@threads') @threads
20+
li
21+
a(href='https://www.threads.net/@instagram') @instagram
22+
li
23+
a(href='https://www.threads.net/@facebook') @facebook
24+
25+
form.profileLookup(action='/profileLookup' id='form' method='GET')
26+
input(type='text' placeholder='Enter the username of a Threads profile to lookup' name='profile' autocomplete='off')
27+
28+
input(type='submit' value='Search')
29+
30+
if username
31+
div
32+
.pictures
33+
.profile-picture
34+
img(src=profilePictureUrl alt='User\'s profile picture' width=36 height=36)
35+
.verified
36+
if isVerified
37+
img(src='/img/verified.png' alt='Verified Badge' width=20 height=20)
38+
39+
table
40+
tbody
41+
tr
42+
th(colspan=2) Username
43+
td(colspan=2)=username
44+
tr
45+
th(colspan=2) Display Name
46+
td(colspan=2)=displayName
47+
tr
48+
th(colspan=2) Bio
49+
td(colspan=2)=bio
50+
tr
51+
th(colspan=2) Followers
52+
td(colspan=2)=followerCount
53+
tr
54+
th(colspan=2) Likes
55+
td(colspan=2)=likesCount
56+
tr
57+
th(colspan=2) Quotes
58+
td(colspan=2)=quotesCount
59+
tr
60+
th(colspan=2) Replies
61+
td(colspan=2)=repliesCount
62+
tr
63+
th(colspan=2) Reposts
64+
td(colspan=2)=repostsCount
65+
tr
66+
th(colspan=2) Views
67+
td(colspan=2)=viewsCount

0 commit comments

Comments
 (0)