24 lines
678 B
TypeScript
24 lines
678 B
TypeScript
export async function getTiktokFollowerCount(): Promise<number | null> {
|
|
const apiKey = process.env.TIKTOK_API_KEY;
|
|
const userId = process.env.TIKTOK_USER_ID;
|
|
if (!apiKey || !userId) return null;
|
|
|
|
try {
|
|
const res = await fetch(
|
|
`https://api.scrapecreators.com/v1/tiktok/profile?user_id=${encodeURIComponent(userId)}`,
|
|
{
|
|
headers: { 'x-api-key': apiKey },
|
|
next: { revalidate: 86400 },
|
|
signal: AbortSignal.timeout(5000),
|
|
}
|
|
);
|
|
if (!res.ok) return null;
|
|
|
|
const data = await res.json();
|
|
const count = data.statsV2?.followerCount;
|
|
return count != null ? Number(count) : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|