> ## 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.

# Recent Post Counts

> 이 가이드에서는 최근 7일간의 Post counts(볼륨)를 가져오는 방법을 안내합니다. 퀵스타트를 다루는 X API v2 standard 티어 레퍼런스입니다.

export const Button = ({href, children}) => {
  return <div className="not-prose">
    <a href={href}>
      <button className="x-btn">
        <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>;
};

이 가이드에서는 최근 7일간의 Post counts(볼륨)를 가져오는 방법을 안내합니다.

<Note>
  **사전 요구사항**

  시작하기 전에 다음이 필요합니다:

  * 승인된 App이 있는 [developer account](https://developer.x.com/en/portal/petition/essential/basic-info)
  * App의 Bearer Token
</Note>

***

## 최근 Post counts 가져오기

<Steps>
  <Step title="쿼리 작성">
    recent search와 동일한 쿼리 구문을 사용합니다. 예를 들어 @XDevelopers의 게시물 수를 세려면:

    ```
    from:XDevelopers
    ```
  </Step>

  <Step title="요청 보내기">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/tweets/counts/recent?\
      query=from%3AXDevelopers&\
      granularity=day" \
        -H "Authorization: Bearer $BEARER_TOKEN"
      ```

      ```python title="Python SDK" lines wrap icon="python" theme={null}
      from xdk import Client

      client = Client(bearer_token="YOUR_BEARER_TOKEN")

      # Get recent Post counts
      response = client.posts.count_recent(
          query="from:XDevelopers",
          granularity="day"
      )

      for bucket in response.data:
          print(f"{bucket.start}: {bucket.tweet_count} Posts")

      print(f"Total: {response.meta.total_tweet_count}")
      ```

      ```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
      import { Client } from "@xdevplatform/xdk";

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

      // Get recent Post counts
      const response = await client.posts.countRecent({
        query: "from:XDevelopers",
        granularity: "day",
      });

      response.data?.forEach((bucket) => {
        console.log(`${bucket.start}: ${bucket.tweet_count} Posts`);
      });

      console.log(`Total: ${response.meta?.total_tweet_count}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="응답 확인">
    ```json theme={null}
    {
      "data": [
        {
          "end": "2024-01-16T00:00:00.000Z",
          "start": "2024-01-15T00:00:00.000Z",
          "tweet_count": 5
        },
        {
          "end": "2024-01-17T00:00:00.000Z",
          "start": "2024-01-16T00:00:00.000Z",
          "tweet_count": 3
        },
        {
          "end": "2024-01-18T00:00:00.000Z",
          "start": "2024-01-17T00:00:00.000Z",
          "tweet_count": 8
        }
      ],
      "meta": {
        "total_tweet_count": 16
      }
    }
    ```
  </Step>
</Steps>

***

## Granularity 옵션

카운트가 어떻게 그룹화되는지 제어합니다:

| Granularity | Description     |
| :---------- | :-------------- |
| `minute`    | 분 단위 카운트        |
| `hour`      | 시간 단위 카운트 (기본값) |
| `day`       | 일 단위 카운트        |

<CodeGroup dropdown>
  ```bash cURL theme={null}
  # Get hourly counts
  curl "https://api.x.com/2/tweets/counts/recent?\
  query=python%20lang%3Aen&\
  granularity=hour" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

  ```python title="Python SDK" lines wrap icon="python" theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # Get hourly counts
  response = client.posts.count_recent(
      query="python lang:en",
      granularity="hour"
  )

  for bucket in response.data:
      print(f"{bucket.start}: {bucket.tweet_count}")
  ```

  ```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
  import { Client } from "@xdevplatform/xdk";

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

  // Get hourly counts
  const response = await client.posts.countRecent({
    query: "python lang:en",
    granularity: "hour",
  });

  response.data?.forEach((bucket) => {
    console.log(`${bucket.start}: ${bucket.tweet_count}`);
  });
  ```
</CodeGroup>

***

## 시간 범위로 필터링

카운트를 특정 기간으로 한정합니다:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/tweets/counts/recent?\
  query=from%3AXDevelopers&\
  start_time=2024-01-10T00%3A00%3A00Z&\
  end_time=2024-01-15T00%3A00%3A00Z&\
  granularity=day" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

  ```python title="Python SDK" lines wrap icon="python" theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # Get counts for a specific time range
  response = client.posts.count_recent(
      query="from:XDevelopers",
      start_time="2024-01-10T00:00:00Z",
      end_time="2024-01-15T00:00:00Z",
      granularity="day"
  )

  print(f"Total Posts: {response.meta.total_tweet_count}")
  ```

  ```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
  import { Client } from "@xdevplatform/xdk";

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

  // Get counts for a specific time range
  const response = await client.posts.countRecent({
    query: "from:XDevelopers",
    startTime: "2024-01-10T00:00:00Z",
    endTime: "2024-01-15T00:00:00Z",
    granularity: "day",
  });

  console.log(`Total Posts: ${response.meta?.total_tweet_count}`);
  ```
</CodeGroup>

***

## 공통 파라미터

| Parameter     | Description             | Default |
| :------------ | :---------------------- | :------ |
| `query`       | 검색 쿼리 (필수)              | —       |
| `granularity` | 시간 버킷 크기                | `hour`  |
| `start_time`  | 가장 오래된 타임스탬프 (ISO 8601) | 7일 전    |
| `end_time`    | 가장 최근 타임스탬프 (ISO 8601)  | 현재      |

***

## 다음 단계

<CardGroup cols={2}>
  <Card title="Full-archive counts" icon="vault" href="/x-api/posts/counts/quickstart/full-archive-tweet-counts">
    과거 Post counts 가져오기
  </Card>

  <Card title="쿼리 작성" icon="https://mintcdn.com/x-preview/cfyQtgCdwk8p69aa/icons/xds/icon-search.svg?fit=max&auto=format&n=cfyQtgCdwk8p69aa&q=85&s=8c11ad89387b7c09ced1553d5c232834" href="/x-api/posts/counts/integrate/build-a-query" width="24" height="24" data-path="icons/xds/icon-search.svg">
    쿼리 구문 마스터하기
  </Card>

  <Card title="API 레퍼런스" icon="https://mintcdn.com/x-preview/ygI6sSJPehlc0qNT/icons/xds/icon-code.svg?fit=max&auto=format&n=ygI6sSJPehlc0qNT&q=85&s=488e23401b19225b89acc0136d242219" href="/x-api/posts/get-count-of-recent-posts" width="24" height="24" data-path="icons/xds/icon-code.svg">
    전체 엔드포인트 문서
  </Card>
</CardGroup>
