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;
}