> ## Documentation Index
> Fetch the complete documentation index at: https://docs.x.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript XDK

> 인증, 타입 지정된 응답, 페이지네이션 및 스트리밍 예제와 함께 X API v2를 위한 공식 TypeScript XDK 클라이언트 라이브러리를 설치하고 사용합니다.

[TypeScript XDK](https://github.com/xdevplatform/twitter-api-typescript-sdk)는 X API v2의 공식 클라이언트 라이브러리입니다. 완전한 타입 안전성, 자동 페이지네이션 및 이벤트 기반 스트리밍을 제공합니다.

<Card title="GitHub 저장소" icon="github" href="https://github.com/xdevplatform/twitter-api-typescript-sdk">
  소스 코드, 이슈 및 릴리스.
</Card>

***

## 설치

<CodeGroup>
  ```bash npm theme={null}
  npm install @xdevplatform/xdk
  ```

  ```bash yarn theme={null}
  yarn add @xdevplatform/xdk
  ```

  ```bash pnpm theme={null}
  pnpm add @xdevplatform/xdk
  ```
</CodeGroup>

Node.js 16+ 및 TypeScript 4.5+가 필요합니다(TypeScript 사용 시).

***

## 빠른 시작

```typescript theme={null}
import { Client } from '@xdevplatform/xdk';

const client = new Client({ bearerToken: 'YOUR_BEARER_TOKEN' });

const userResponse = await client.users.getByUsername('XDevelopers');
console.log(userResponse.data?.username);
```

***

## 주요 기능

| 기능            | 설명                                            |
| :------------ | :-------------------------------------------- |
| **타입 안전성**    | 모든 엔드포인트 및 매개변수에 대한 완전한 TypeScript 정의         |
| **인증**        | Bearer Token, PKCE가 포함된 OAuth 2.0, OAuth 1.0a |
| **자동 페이지네이션** | 페이지네이션된 엔드포인트에 대한 비동기 반복 지원                   |
| **스트리밍**      | 자동 재연결이 있는 이벤트 기반 스트리밍                        |
| **전체 API 지원** | Users, Posts, Lists, Bookmarks, Communities 등 |

***

## 인증

<Tabs>
  <Tab title="Bearer Token">
    ```typescript theme={null}
    import { Client } from '@xdevplatform/xdk';

    const client = new Client({ bearerToken: 'YOUR_BEARER_TOKEN' });
    ```
  </Tab>

  <Tab title="OAuth 2.0">
    ```typescript theme={null}
    import { Client, OAuth2, generateCodeVerifier, generateCodeChallenge } from '@xdevplatform/xdk';

    const oauth2 = new OAuth2({
      clientId: 'YOUR_CLIENT_ID',
      clientSecret: 'YOUR_CLIENT_SECRET',
      redirectUri: 'https://your-app.com/callback',
      scope: ['tweet.read', 'users.read', 'offline.access'],
    });

    const codeVerifier = generateCodeVerifier();
    const codeChallenge = await generateCodeChallenge(codeVerifier);
    oauth2.setPkceParameters(codeVerifier, codeChallenge);
    const authUrl = await oauth2.getAuthorizationUrl('state');

    const tokens = await oauth2.exchangeCode(authCode, codeVerifier);
    const client = new Client({ accessToken: tokens.access_token });
    ```
  </Tab>

  <Tab title="OAuth 1.0a">
    ```typescript theme={null}
    import { Client, OAuth1 } from '@xdevplatform/xdk';

    const oauth1 = new OAuth1({
      apiKey: 'YOUR_API_KEY',
      apiSecret: 'YOUR_API_SECRET',
      accessToken: 'YOUR_ACCESS_TOKEN',
      accessTokenSecret: 'YOUR_ACCESS_TOKEN_SECRET'
    });

    const client = new Client({ oauth1: oauth1 });
    ```
  </Tab>
</Tabs>

***

## 일반적인 메서드

| 카테고리       | 메서드                              |
| :--------- | :------------------------------- |
| **Posts**  | `client.posts.search()`          |
| **Users**  | `client.users.getMe()`           |
| **Spaces** | `client.spaces.findSpaceById()`  |
| **Lists**  | `client.lists.getList()`         |
| **DMs**    | `client.directMessages.lookup()` |

***

## 자세히 알아보기

<CardGroup cols={2}>
  <Card title="설치" icon="download" href="/xdks/typescript/install">
    패키지 관리자, TypeScript 설정 및 요구 사항.
  </Card>

  <Card title="인증" icon="key" href="/xdks/typescript/authentication">
    모든 인증 방법에 대한 자세한 가이드.
  </Card>

  <Card title="페이지네이션" icon="arrows-left-right" href="/xdks/typescript/pagination">
    비동기 반복 및 페이지네이션된 응답.
  </Card>

  <Card title="스트리밍" icon="satellite-dish" href="/xdks/typescript/streaming">
    재연결이 있는 이벤트 기반 스트리밍.
  </Card>

  <Card title="API 레퍼런스" icon="book" href="/xdks/typescript/reference/modules">
    전체 클라이언트, 인터페이스 및 타입 레퍼런스.
  </Card>
</CardGroup>

코드 예제는 [samples 저장소](https://github.com/xdevplatform/samples/tree/main/javascript)를 참조하세요.
