Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export async function fetchTwitterUser({ id, accessToken, query = "" }: {
id: string;
accessToken: string;
query?: string;
}): Promise<{
id: string;
name: string;
username: string;
public_metrics?: {
followers_count: number;
following_count: number;
tweet_count: number;
listed_count: number;
};
}> {
const res = await fetchJSON(
`https://api.twitter.com/2/users/${id}?${query}`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
);
if (!res.data) {
throw new Error(`Failed to get user:\n${JSON.stringify(res)}`);
}
return res.data;
}
October 23, 2023