haixunMaster/lib/threads-api/posts.ts

31 lines
706 B
TypeScript
Raw Permalink Normal View History

2026-06-21 12:50:31 +00:00
import { threadsGraphGet } from "./client";
import type { ThreadsApiCredentials } from "./types";
export interface ThreadsOwnPost {
id: string;
text?: string;
permalink?: string;
timestamp?: string;
media_type?: string;
}
interface ThreadsOwnPostsResponse {
data?: ThreadsOwnPost[];
}
export async function getOwnPostsViaThreadsApi(
credentials: ThreadsApiCredentials,
limit = 25
): Promise<ThreadsOwnPost[]> {
const json = await threadsGraphGet<ThreadsOwnPostsResponse>(
`/${credentials.userId}/threads`,
{
access_token: credentials.accessToken,
fields: "id,text,permalink,timestamp,media_type",
limit: String(limit),
}
);
return json.data ?? [];
}