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

# 全アーカイブのポスト数

> 2006年まで遡ってポスト数の履歴件数を取得します

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>;
};

このガイドでは、2006年3月まで遡るポスト数の履歴を取得する方法を説明します。

<Warning>
  フルアーカイブのポスト数を取得するには、[Self-serve](/ja/x-api/getting-started/about-x-api) または [Enterprise](/ja/x-api/getting-started/about-x-api) へのアクセスが必要です。
</Warning>

<Note>
  **前提条件**

  始める前に、以下を用意してください。

  * Self-serve または Enterprise にアクセス可能な[開発者アカウント](https://developer.x.com/en/portal/petition/essential/basic-info)
  * ご利用の App のベアラートークン
</Note>

***

<div id="get-full-archive-post-counts">
  ## 全アーカイブの投稿数を取得する
</div>

<Steps>
  <Step title="クエリを作成する">
    全アーカイブ検索と同じクエリ構文を使用します。たとえば、@XDevelopers からの投稿数を取得するには次のようにします:

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

  <Step title="時間範囲を設定する">
    特定の過去期間を検索するために `start_time` と `end_time` を指定します:

    | パラメータ        | 形式       | 例                      |
    | :----------- | :------- | :--------------------- |
    | `start_time` | ISO 8601 | `2020-01-01T00:00:00Z` |
    | `end_time`   | ISO 8601 | `2020-12-31T23:59:59Z` |
  </Step>

  <Step title="リクエストを送信する">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/tweets/counts/all?\
      query=from%3AXDevelopers&\
      start_time=2020-01-01T00%3A00%3A00Z&\
      end_time=2020-12-31T23%3A59%3A59Z&\
      granularity=day" \
        -H "Authorization: Bearer $BEARER_TOKEN"
      ```

      ```python Python SDK theme={null}
      from xdk import Client

      client = Client(bearer_token="YOUR_BEARER_TOKEN")

      # 全アーカイブの投稿数を取得
      response = client.posts.count_all(
          query="from:XDevelopers",
          start_time="2020-01-01T00:00:00Z",
          end_time="2020-12-31T23:59:59Z",
          granularity="day"
      )

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

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

      ```javascript JavaScript SDK theme={null}
      import { Client } from "@xdevplatform/xdk";

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

      // Get full-archive Post counts
      const response = await client.posts.countAll({
        query: "from:XDevelopers",
        startTime: "2020-01-01T00:00:00Z",
        endTime: "2020-12-31T23:59:59Z",
        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": "2020-01-02T00:00:00.000Z",
          "start": "2020-01-01T00:00:00.000Z",
          "tweet_count": 3
        },
        {
          "end": "2020-01-03T00:00:00.000Z",
          "start": "2020-01-02T00:00:00.000Z",
          "tweet_count": 5
        }
      ],
      "meta": {
        "total_tweet_count": 8
      }
    }
    ```
  </Step>
</Steps>

***

<div id="granularity-options">
  ## 粒度オプション
</div>

カウントの集計単位を制御します。

| 粒度       | 説明                |
| :------- | :---------------- |
| `minute` | 分ごとのカウント          |
| `hour`   | 時間ごとのカウント (デフォルト) |
| `day`    | 日ごとのカウント          |

***

<div id="paginate-through-results">
  ## ページネーションで結果を取得する
</div>

期間が長い場合は、レスポンスに含まれる `next_token` を使用します。

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/tweets/counts/all?\
  query=from%3AXDevelopers&\
  start_time=2015-01-01T00%3A00%3A00Z&\
  end_time=2020-12-31T23%3A59%3A59Z&\
  granularity=day&\
  next_token=abc123" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # ページネーションを使用して件数を取得
  next_token = None

  while True:
      response = client.posts.count_all(
          query="from:XDevelopers",
          start_time="2015-01-01T00:00:00Z",
          end_time="2020-12-31T23:59:59Z",
          granularity="day",
          next_token=next_token
      )
      
      for bucket in response.data:
          print(f"{bucket.start}: {bucket.tweet_count}")
      
      next_token = response.meta.next_token
      if not next_token:
          break
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

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

  // ページネーションを使用して件数を取得
  let nextToken = undefined;

  do {
    const response = await client.posts.countAll({
      query: "from:XDevelopers",
      startTime: "2015-01-01T00:00:00Z",
      endTime: "2020-12-31T23:59:59Z",
      granularity: "day",
      nextToken,
    });

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

    nextToken = response.meta?.next_token;
  } while (nextToken);
  ```
</CodeGroup>

***

<div id="key-differences-from-recent-counts">
  ## 最近の件数との主な違い
</div>

| 機能         | Recent Counts | Full-Archive Counts |
| :--------- | :------------ | :------------------ |
| 時間範囲       | 直近7日間         | 2006年3月から現在まで       |
| 必要なアクセスレベル | すべての開発者       | 従量課金、エンタープライズ       |
| デフォルトの時間範囲 | 直近7日間         | 直近30日間              |

***

<div id="common-parameters">
  ## 共通パラメーター
</div>

| パラメーター        | 説明                      | デフォルト  |
| :------------ | :---------------------- | :----- |
| `query`       | 検索クエリ (必須)              | —      |
| `granularity` | 時間バケットの粒度               | `hour` |
| `start_time`  | 最も古いタイムスタンプ (ISO 8601)  | 30日前   |
| `end_time`    | 最も新しいタイムスタンプ (ISO 8601) | 現在     |
| `next_token`  | ページネーション用トークン           | —      |

***

<div id="next-steps">
  ## 次のステップ
</div>

<CardGroup cols={2}>
  <Card title="最近の件数" icon="clock" href="/ja/x-api/posts/counts/quickstart/recent-tweet-counts">
    直近の投稿数を取得する
  </Card>

  <Card title="クエリを構築する" icon="magnifying-glass" href="/ja/x-api/posts/counts/integrate/build-a-query">
    クエリ構文を使いこなす
  </Card>

  <Card title="APIリファレンス" icon="code" href="/ja/x-api/posts/full-archive-post-count">
    エンドポイントの完全なドキュメント
  </Card>
</CardGroup>
