ページネーション
アーカイブの取得
Section titled “アーカイブの取得”listArchives はカーソルベースのページネーションで Page<Archive> を返します:
const page = await client.listArchives("youtube", channelId);
console.log(page.items); // Archive[]console.log(page.cursor); // string | undefined — 次ページ取得用console.log(page.hasMore); // boolean — 次のページが存在する場合 trueconsole.log(page.total); // number | undefined — 総数(取得可能な場合)複数ページの取得
Section titled “複数ページの取得”let cursor: string | undefined;const allArchives: Archive[] = [];
do { const page = await client.listArchives("youtube", channelId, cursor); allArchives.push(...page.items); cursor = page.cursor;} while (cursor);
console.log(`${allArchives.length} 件のアーカイブを取得しました`);ページ数を制限して取得
Section titled “ページ数を制限して取得”const MAX_PAGES = 3;let cursor: string | undefined;const archives: Archive[] = [];
for (let i = 0; i < MAX_PAGES; i++) { const page = await client.listArchives("twitch", channelId, cursor); archives.push(...page.items); cursor = page.cursor; if (!cursor) break;}アーカイブのフィルタリング
Section titled “アーカイブのフィルタリング”ArchiveListOptions を渡して、期間・ソート順・動画タイプでフィルタリングできます(プラットフォームによりサポート状況が異なります):
const page = await client.listArchives( "twitch", // プラットフォーム channelId, // チャンネル ID undefined, // カーソル(最初のページ) 20, // ページサイズ { // フィルタオプション period: "week", sort: "views", videoType: "highlight", },);| オプション | 値 | 説明 |
|---|---|---|
period | "all", "day", "week", "month" | 期間フィルタ |
sort | "time", "trending", "views" | ソート順 |
videoType | プラットフォーム固有(例: Twitch の "archive", "highlight", "upload") | 動画タイプフィルタ |
ライブ配信の取得
Section titled “ライブ配信の取得”listBroadcasts はチャンネルの現在のライブ配信をすべて返します。ライブ配信は通常少数なので、ページネーションは不要です。
const streams = await client.listBroadcasts("twitch", channelId);
for (const stream of streams) { console.log(`${stream.title} — ${stream.viewerCount} 人が視聴中`);}次のステップ
Section titled “次のステップ”- 応用 — OpenTelemetry やプラグインの直接アクセス