> ## Documentation Index
> Fetch the complete documentation index at: https://x-preview-mintlify-066e8699.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 첫 요청 보내기

> 인증 설정, 엔드포인트 선택, 샘플 cURL 명령, 응답 처리 팁을 포함하여 첫 X Enterprise API 요청을 보내세요.

export const Button = ({href, children}) => {
  return <div className="not-prose group">
    <a href={href}>
      <button className="flex items-center space-x-2.5 py-1 px-4 bg-primary-dark dark:bg-white text-white dark:text-gray-950 rounded-full group-hover:opacity-[0.9] font-medium">
        <span>
          {children}
        </span>
        <svg width="3" height="24" viewBox="0 -9 3 24" class="h-6 rotate-0 overflow-visible"><path d="M0 0L3 3L0 6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"></path></svg>
      </button>
    </a>
  </div>;
};

이 가이드는 첫 X API 요청을 보내는 과정을 안내합니다. 시작하기 전에 [앱 자격 증명이 있는 개발자 계정](/x-api/getting-started/getting-access)이 필요합니다.

***

## cURL로 빠르게 시작하기

API를 테스트하는 가장 빠른 방법은 cURL입니다. 사용자를 조회해 봅시다:

```bash theme={null}
curl "https://api.x.com/2/users/by/username/xdevelopers" \
  -H "Authorization: Bearer $BEARER_TOKEN"
```

`$BEARER_TOKEN`을 실제 Bearer Token으로 바꾸세요. 다음과 같은 응답을 받게 됩니다:

```json theme={null}
{
  "data": {
    "id": "2244994945",
    "name": "X Developers",
    "username": "xdevelopers"
  }
}
```

***

## 단계별 가이드

<Steps>
  <Step title="Bearer Token 받기">
    [Developer Console](https://console.x.com)에서 앱으로 이동해 Bearer Token을 복사하세요.
  </Step>

  <Step title="엔드포인트 선택">
    다음 입문자 친화적인 엔드포인트 중 하나로 시작하세요:

    | 엔드포인트                                             | 기능                       |
    | :------------------------------------------------ | :----------------------- |
    | [User lookup](/x-api/users/lookup/introduction)   | 사용자명 또는 ID로 사용자 프로필 가져오기 |
    | [Post lookup](/x-api/posts/lookup/introduction)   | ID로 게시물 가져오기             |
    | [Recent search](/x-api/posts/search/introduction) | 최근 7일간의 게시물 검색           |
  </Step>

  <Step title="요청 보내기">
    cURL, Postman 또는 선호하는 HTTP 클라이언트를 사용하세요:

    ```bash theme={null}
    # Look up a user by username
    curl "https://api.x.com/2/users/by/username/xdevelopers" \
      -H "Authorization: Bearer $BEARER_TOKEN"
    ```
  </Step>

  <Step title="응답 파싱">
    응답은 JSON 형식입니다. 기본 데이터는 `data` 필드에 있습니다:

    ```json theme={null}
    {
      "data": {
        "id": "2244994945",
        "name": "X Developers",
        "username": "xdevelopers"
      }
    }
    ```
  </Step>
</Steps>

***

## fields로 더 많은 데이터 요청하기

기본적으로 엔드포인트는 최소한의 필드만 반환합니다. 추가 데이터를 요청하려면 `fields` 매개변수를 사용하세요:

```bash theme={null}
curl "https://api.x.com/2/users/by/username/xdevelopers?user.fields=created_at,description,public_metrics" \
  -H "Authorization: Bearer $BEARER_TOKEN"
```

응답:

```json theme={null}
{
  "data": {
    "id": "2244994945",
    "name": "X Developers",
    "username": "xdevelopers",
    "created_at": "2013-12-14T04:35:55.000Z",
    "description": "The voice of the X Developer Platform",
    "public_metrics": {
      "followers_count": 570842,
      "following_count": 2048,
      "tweet_count": 14052,
      "listed_count": 1672
    }
  }
}
```

[fields에 대해 자세히 알아보기 →](/x-api/fundamentals/fields)

***

## 더 많은 예제

<Tabs>
  <Tab title="게시물 조회">
    ```bash theme={null}
    curl "https://api.x.com/2/tweets/1460323737035677698?tweet.fields=created_at,public_metrics" \
      -H "Authorization: Bearer $BEARER_TOKEN"
    ```
  </Tab>

  <Tab title="최근 게시물 검색">
    ```bash theme={null}
    curl "https://api.x.com/2/tweets/search/recent?query=from:xdevelopers&tweet.fields=created_at" \
      -H "Authorization: Bearer $BEARER_TOKEN"
    ```
  </Tab>

  <Tab title="사용자의 게시물 가져오기">
    ```bash theme={null}
    curl "https://api.x.com/2/users/2244994945/tweets?max_results=5" \
      -H "Authorization: Bearer $BEARER_TOKEN"
    ```
  </Tab>
</Tabs>

***

## cURL 대신 코드 사용하기

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import requests

    bearer_token = "YOUR_BEARER_TOKEN"
    url = "https://api.x.com/2/users/by/username/xdevelopers"

    headers = {"Authorization": f"Bearer {bearer_token}"}
    response = requests.get(url, headers=headers)

    print(response.json())
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const bearerToken = "YOUR_BEARER_TOKEN";
    const url = "https://api.x.com/2/users/by/username/xdevelopers";

    fetch(url, {
      headers: { Authorization: `Bearer ${bearerToken}` }
    })
      .then(res => res.json())
      .then(data => console.log(data));
    ```
  </Tab>

  <Tab title="공식 SDK">
    프로덕션 환경에서는 공식 SDK 사용을 권장합니다:

    * [Python SDK](/xdks/python/overview)
    * [TypeScript SDK](/xdks/typescript/overview)

    인증, 페이지네이션, 속도 제한을 자동으로 처리합니다.
  </Tab>
</Tabs>

***

## 테스트 도구

<CardGroup cols={3}>
  <Card title="Postman" icon="server" href="/tutorials/postman-getting-started">
    컬렉션으로 시각적 API 테스트를 수행합니다.
  </Card>

  <Card title="샘플 코드" icon="github" href="https://github.com/xdevplatform/Twitter-API-v2-sample-code">
    여러 언어로 된 예제입니다.
  </Card>

  <Card title="API 레퍼런스" icon="code" href="/x-api/posts/lookup/introduction">
    전체 엔드포인트 문서입니다.
  </Card>
</CardGroup>

***

## 문제 해결

<Accordion title="401 Unauthorized">
  * Bearer Token이 올바른지 확인하세요
  * 토큰이 재발급되지 않았는지 확인하세요
  * `Authorization` 헤더 형식을 확인하세요: `Bearer YOUR_TOKEN`
</Accordion>

<Accordion title="403 Forbidden">
  * 앱에 이 엔드포인트 액세스 권한이 없을 수 있습니다
  * 일부 엔드포인트는 사용자 컨텍스트 인증(OAuth 1.0a 또는 2.0)이 필요합니다
  * Developer Console에서 앱의 권한을 확인하세요
</Accordion>

<Accordion title="429 Too Many Requests">
  * 속도 제한에 도달했습니다
  * 재시도 시점을 확인하려면 `x-rate-limit-reset` 헤더를 확인하세요
  * 코드에 지수 백오프를 구현하세요
</Accordion>

[전체 오류 레퍼런스 →](/x-api/fundamentals/response-codes-and-errors)

***

## 다음 단계

<CardGroup cols={2}>
  <Card title="인증 배우기" icon="key" href="/resources/fundamentals/authentication/overview">
    사용자 컨텍스트 요청을 위한 OAuth를 이해하세요.
  </Card>

  <Card title="엔드포인트 살펴보기" icon="compass" href="/x-api/posts/search/introduction">
    무엇을 만들 수 있는지 알아보세요.
  </Card>

  <Card title="SDK 사용" icon="cube" href="/tools-and-libraries">
    공식 라이브러리로 더 빠르게 개발하세요.
  </Card>

  <Card title="무언가 만들기" icon="hammer" href="/x-api/what-to-build">
    무엇을 만들지에 대한 아이디어입니다.
  </Card>
</CardGroup>
