UNPKG

@upstart.gg/sdk

Version:

You can test the CLI without recompiling by running:

41 lines (39 loc) 1.35 kB
import { UnauthorizedError } from "../../../../errors.js"; import { stringifyObjectValues } from "../../../utils.js"; import invariant from "../../../../utils/invariant.js"; //#region src/shared/datasources/external/threads/media/fetcher.ts /** * todo: add a way to retrieve media/posts from Threads for a given user other than "me" */ const fetchThreadsMediaDatasource = async ({ options, oauth }) => { invariant(oauth?.config, "fetchThreadsMediaDatasource Error: OAuth config is required"); const params = new URLSearchParams({ ...stringifyObjectValues(options), access_token: oauth.config.accessToken, fields: [ "id", "media_product_type", "media_type", "media_url", "permalink", "owner", "username", "text", "timestamp", "shortcode", "thumbnail_url", "children", "is_quote_post" ].join(",") }); const response = await fetch(`https://graph.threads.net/v1.0/me/threads?${params.toString()}`); if (!response.ok) { if (response.status === 401) throw new UnauthorizedError(`fetchThreadsMediaDatasource Error: Unauthorized.`); throw new Error(`fetchThreadsMediaDatasource Error: Response status: ${response.status}`); } return await response.json(); }; var fetcher_default = fetchThreadsMediaDatasource; //#endregion export { fetcher_default as default }; //# sourceMappingURL=fetcher.js.map