Documentation Index
Fetch the complete documentation index at: https://generaltranslation.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
TypeScript SDK は、ライブデータフィード向けのリアルタイムのストリーミング機能を提供します。
リアルタイムのサンプル投稿ストリームに接続する:
import { Client } from '@xdevplatform/xdk';
const client: Client = new Client({ bearerToken: 'your-bearer-token' });
// 公開投稿の1%サンプル
const stream = await client.stream.postsSample({
tweetFields: ['id','text','created_at'],
expansions: ['author_id'],
userFields: ['id','username','name']
});
// イベントを監視
stream.on('data', (event) => {
// event はパース済みの JSON 行 (data/includes/matching_rules)
console.log('New data:', event);
});
stream.on('error', (e) => console.error('Stream error:', e));
stream.on('close', () => console.log('Stream closed'));
非同期イテレーションでストリームを処理します:
const stream = await client.stream.postsSample();
for await (const event of stream) {
// 各イベントは解析済みの JSON 行(data/includes/matching_rules)です
console.log(event);
}
イベント駆動ストリーム側からライフサイクルを制御する:
// ストリームを閉じる
stream.close();
// 自動再接続(ラッパーで有効にしている場合)
// デフォルトのEventDrivenStreamは基本的な再接続フックを公開する
ストリーミング中のerrorsと再接続を処理します。
stream.on('error', (event) => {
const err = event.error || event;
console.error('Stream error:', err);
});
stream.on('keepAlive', () => {
// ハートビートイベント
});