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

# クイックスタート

このサンプルでは、XDK を使い、ベアラートークン認証で投稿をすばやく検索する方法を示します。

<div id="step-1-install-the-sdk">
  ## ステップ 1：SDK をインストールする
</div>

```bash theme={null}
pip install xdk
```

<div id="step-2-get-your-bearer-token">
  ## ステップ 2: ベアラートークンを取得する
</div>

1. [X 開発者コンソール](https://developer.x.com/en/portal/dashboard) にログインします。
2. App を新規作成するか、既存の App を選択します。
3. 「Keys and Tokens」セクションで、ベアラートークン (App-only 認証) を発行します。

<div id="step-3-write-and-run-your-first-script">
  ## ステップ 3: 最初のスクリプトを作成して実行する
</div>

`quickstart.py` という名前のファイルを作成します:

```python theme={null}
# Import the client
from xdk import Client
# Replace with your actual Bearer Token
client = Client(bearer_token="YOUR_BEARER_TOKEN_HERE")
# Fetch recent Posts mentioning "api"
# search_recent returns an Iterator, so iterate over it
for page in client.posts.search_recent(query="api", max_results=10):
    if page.data and len(page.data) > 0:
        # 最初の投稿にアクセス - Pydanticモデルは属性とdict両方のアクセスをサポート
        first_post = page.data[0]
        post_text = first_post.text if hasattr(first_post, 'text') else first_post.get('text', '')
        print(f"Latest Post: {post_text}")
        break
    else:
        print("No Posts found.")
        break
```

実行します:

```bash theme={null}
python quickstart.py
```

**期待される出力**:

```
最新のポスト: XDK Python SDKのエキサイティングなアップデート!
```

**トラブルシューティング**：401 エラーが発生した場合は、ベアラートークンを再確認してください。レート制限 (429) エラーの場合は、時間をおいてから再試行してください。

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

* [Authentication](/ja/xdks/python/authentication) を確認して、ベアラートークン (app-only) 認証、PKCE を用いた OAuth 2.0 (ユーザーコンテキスト) 、および OAuth 1.0a (レガシーなユーザーコンテキスト) の使い方を理解しましょう。
* 大量の結果を、複数回の API 呼び出しを気にせず取得したいユースケース向けに、[Pagination](/ja/xdks/python/pagination) について学びましょう。
* [Streaming](/ja/xdks/python/streaming) をさらに掘り下げて、リアルタイムデータの扱い方を学びましょう。
  Python XDK を使用した詳細なコード例については、[code samples GitHub リポジトリ](https://github.com/xdevplatform/samples/tree/main/python)を参照してください。
