メインコンテンツへスキップ
X API 向けのメイン Client クラス これは X API とやり取りするための主なエントリポイントです。専用のクライアントモジュールを通じてすべての API エンドポイントへアクセスする手段を提供し、認証、リクエスト設定、エラーハンドリングを担います。 Example
import { Client } from '@xdevplatform/xdk';

const client = new Client({
  bearerToken: 'your-bearer-token'
});

// ユーザー情報を取得する
const user = await client.users.getUser('783214');

// ページネーションを使用してフォロワーを取得する
const followers = await client.users.getFollowers('783214', {
  maxResults: 10,
  userFields: ['id', 'name', 'username']
});

// フォロワーを反復処理する
for await (const follower of followers) {
  console.log(follower.username);
}

コンストラクタ

constructor

new Client(config): Client 新しい X API クライアント インスタンスを作成します。

パラメーター

名前type説明
configanyClient 用の設定オプション

戻り値

Client 使用例
// ベアラートークン認証
const client = new Client({
  bearerToken: 'your-bearer-token'
});

// OAuth2 認証
const client = new Client({
  accessToken: 'your-access-token'
});

// OAuth1 認証
const client = new Client({
  oauth1: oauth1Instance
});
client.ts:401

プロパティ

baseUrl
string
必須
API リクエスト用のベース URL
bearerToken
string
認証に使用するベアラートークン
accessToken
string
OAuth2 アクセストークン
oauth1
any
認証に使用する OAuth1 インスタンス
headers
Headers
必須
リクエスト用ヘッダー
timeout
number
必須
ミリ秒単位のリクエストタイムアウト
retry
boolean
必須
失敗したリクエストを自動で再試行するかどうか
maxRetries
number
必須
再試行回数の上限
httpClient
HttpClient = httpClient
必須
リクエストの送信に使用する HTTP クライアント
general
GeneralClient
必須
general クライアント
accountActivity
AccountActivityClient
必須
account activity クライアント
communityNotes
CommunityNotesClient
必須
community notes クライアント
compliance
ComplianceClient
必須
compliance クライアント
connections
ConnectionsClient
必須
connections クライアント
users
UsersClient
必須
users クライアント
news
NewsClient
必須
news クライアント
spaces
SpacesClient
必須
spaces クライアント
activity
ActivityClient
必須
activity クライアント
usage
UsageClient
必須
usage クライアント
trends クライアント
posts
PostsClient
必須
posts クライアント
directMessages
DirectMessagesClient
必須
direct messages クライアント
communities
CommunitiesClient
必須
communities クライアント
media
MediaClient
必須
media クライアント
webhooks
WebhooksClient
必須
webhooks クライアント
stream
StreamClient
必須
stream クライアント
lists
ListsClient
必須
lists クライアント
request
Promise<T>
必須
X API への認証済みリクエストを実行しますこのメソッドは、すべての API リクエストについて、認証、リクエストのフォーマット、 およびエラー処理を行います。クライアント設定に基づいて、適切な認証ヘッダーを自動的に追加します。
isTokenExpired
boolean
必須
OAuth2 トークンが有効期限切れかどうかを確認します
refreshToken
Promise<void>
必須
OAuth2 トークンをリフレッシュします
isAuthenticated
boolean
必須
現在の認証状態を取得します
mapSecuritySchemeToAuthTypes
string[]
必須
OpenAPI のセキュリティスキーム名を内部の認証タイプにマッピングします
validateAuthentication
void
必須
必要な認証方式が利用可能であることを検証します
getAvailableAuthTypes
string[]
必須
利用可能な認証タイプを取得します