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

# Full-Archive Search クイックスタート

> 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月までさかのぼる完全な X アーカイブから投稿を検索するために、最初のフルアーカイブ検索リクエストを実行する手順を順を追って説明します。

<Warning>
  フルアーカイブ検索を利用するには、[セルフサービス](/ja/x-api/getting-started/about-x-api)または[エンタープライズ](/ja/x-api/getting-started/about-x-api)アクセスが必要です。このエンドポイントを使用するには、[アクセスをアップグレード](https://developer.x.com/en/portal/products)してください。
</Warning>

<Note>
  **前提条件**

  作業を始める前に、次のものが必要です。

  * [開発者アカウント](https://developer.x.com/en/portal/petition/essential/basic-info)
  * App のベアラートークン (開発者コンソールの「Keys and tokens」で確認できます)
</Note>

***

<div id="step-1-build-a-query">
  ## ステップ 1: クエリを作成する
</div>

Full-archive search では、すべてのクエリオペレーターを利用できます。recent search と同じ要領でクエリを作成してください。

```
from:XDevelopers lang:en
```

<Tip>
  フルアーカイブ検索は、最大 1,024 文字までのクエリをサポートします (Enterprise では 4,096 文字) 。
</Tip>

***

<div id="step-2-set-a-time-range">
  ## ステップ 2: 時間範囲を設定する
</div>

デフォルトでは、直近30日間の投稿が結果として返されます。特定の期間を指定して検索するには、`start_time` と `end_time` を使用します。

| Parameter    | Format   | Example                |
| :----------- | :------- | :--------------------- |
| `start_time` | ISO 8601 | `2020-01-01T00:00:00Z` |
| `end_time`   | ISO 8601 | `2020-12-31T23:59:59Z` |

***

<div id="step-3-make-a-request">
  ## ステップ 3: リクエストを送信する
</div>

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

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

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # ページネーションを用いたフルアーカイブ検索
  for page in client.posts.search_all(
      query="from:XDevelopers",
      start_time="2020-01-01T00:00:00Z",
      end_time="2020-12-31T23:59:59Z",
      max_results=100
  ):
      for post in page.data:
          print(post.text)
  ```

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

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

  // ページネーションを用いたフルアーカイブ検索
  const paginator = client.posts.searchAll({
    query: "from:XDevelopers",
    startTime: "2020-01-01T00:00:00Z",
    endTime: "2020-12-31T23:59:59Z",
    maxResults: 100,
  });

  for await (const page of paginator) {
    page.data?.forEach((post) => {
      console.log(post.text);
    });
  }
  ```
</CodeGroup>

***

<div id="step-4-review-the-response">
  ## ステップ 4：レスポンスを確認する
</div>

```json theme={null}
{
  "data": [
    {
      "id": "1271111223220809728",
      "text": "Tune in tonight and watch as @jessicagarson takes us through...",
      "edit_history_tweet_ids": ["1271111223220809728"]
    },
    {
      "id": "1270799243071062016",
      "text": "As we work towards building the new Twitter API...",
      "edit_history_tweet_ids": ["1270799243071062016"]
    }
  ],
  "meta": {
    "newest_id": "1271111223220809728",
    "oldest_id": "1270799243071062016",
    "result_count": 2
  }
}
```

<Note>
  編集機能が導入される前 (2022年9月) に作成された投稿には、`edit_history_tweet_ids` は含まれません。
</Note>

***

<div id="step-5-add-fields-and-expansions">
  ## ステップ 5: フィールドとexpansionsを追加する
</div>

クエリパラメータを使用して追加のデータをリクエストします:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/tweets/search/all?\
  query=from%3AXDevelopers&\
  start_time=2020-01-01T00%3A00%3A00Z&\
  end_time=2020-12-31T23%3A59%3A59Z&\
  tweet.fields=created_at,public_metrics,author_id&\
  expansions=author_id&\
  user.fields=username,description&\
  max_results=100" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

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

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # フィールドとexpansionsを指定して検索
  for page in client.posts.search_all(
      query="from:XDevelopers",
      start_time="2020-01-01T00:00:00Z",
      end_time="2020-12-31T23:59:59Z",
      tweet_fields=["created_at", "public_metrics", "author_id"],
      expansions=["author_id"],
      user_fields=["username", "description"],
      max_results=100
  ):
      for post in page.data:
          print(f"{post.created_at}: {post.text[:50]}...")
  ```

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

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

  // フィールドとexpansionsを指定して検索
  const paginator = client.posts.searchAll({
    query: "from:XDevelopers",
    startTime: "2020-01-01T00:00:00Z",
    endTime: "2020-12-31T23:59:59Z",
    tweetFields: ["created_at", "public_metrics", "author_id"],
    expansions: ["author_id"],
    userFields: ["username", "description"],
    maxResults: 100,
  });

  for await (const page of paginator) {
    page.data?.forEach((post) => {
      console.log(`${post.created_at}: ${post.text?.slice(0, 50)}...`);
    });
  }
  ```
</CodeGroup>

***

<div id="step-6-paginate-through-results">
  ## ステップ 6: 結果をページングする
</div>

SDK ではページングを自動的に処理します。cURL を使用する場合は、レスポンス内の `next_token` を使用します。

```bash theme={null}
curl "https://api.x.com/2/tweets/search/all?\
query=from%3AXDevelopers&\
max_results=500&\
next_token=b26v89c19zqg8o3fo7gesq314yb9l2l4ptqy" \
  -H "Authorization: Bearer $BEARER_TOKEN"
```

<Card title="ページネーションガイド" icon="arrow-right" href="/ja/x-api/posts/search/integrate/paginate">
  大規模な結果セットをページング処理する方法について詳しく学びましょう
</Card>

***

<div id="key-differences-from-recent-search">
  ## Recent Search との主な違い
</div>

| 機能              | Recent Search         | Full-Archive Search |
| :-------------- | :-------------------- | :------------------ |
| 期間              | 過去7日間                 | 2006年3月から現在まで       |
| 必要なアクセス権限       | すべての開発者               | 従量課金、Enterprise     |
| リクエストあたりの最大取得件数 | 100                   | 500                 |
| クエリ長            | 512文字                 | 1,024文字             |
| レート制限           | 450 / 15分             | 300 / 15分, 1 / 秒    |
| 認証方式            | App-Only、User Context | App-Only のみ         |

***

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

| Parameter      | 説明                   | デフォルト        |
| :------------- | :------------------- | :----------- |
| `query`        | 検索クエリ (必須)           | —            |
| `max_results`  | 1ページあたりの投稿数 (10〜500) | 10           |
| `start_time`   | 最も古いポストのタイムスタンプ      | 30日前         |
| `end_time`     | 最も新しいポストのタイムスタンプ     | 現在           |
| `next_token`   | ページネーション用トークン        | —            |
| `tweet.fields` | 追加で取得するポストのフィールド     | `id`, `text` |
| `expansions`   | レスポンスに含める関連オブジェクト    | —            |

***

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

<CardGroup cols={2}>
  <Card title="クエリを構築する" icon="magnifying-glass" href="/ja/x-api/posts/search/integrate/build-a-query">
    クエリ構文と演算子を習得する
  </Card>

  <Card title="演算子リファレンス" icon="list-check" href="/ja/x-api/posts/search/integrate/operators">
    利用可能なすべての演算子を確認する
  </Card>

  <Card title="ページネーションガイド" icon="arrow-right" href="/ja/x-api/posts/search/integrate/paginate">
    大量の結果セットを処理する
  </Card>

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