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

# クイックスタート

> X 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 を使用して投稿を作成および削除する方法を順を追って説明します。

<Note>
  **前提条件**

  開始する前に、次のものが必要です。

  * 承認済みの App を持つ [開発者アカウント](https://developer.x.com/en/portal/petition/essential/basic-info)
  * ユーザーアクセストークン (OAuth 1.0a または OAuth 2.0 PKCE)
</Note>

***

<div id="create-a-post">
  ## ポストを作成する
</div>

<Steps>
  <Step title="リクエストを準備する">
    POST `/2/tweets` エンドポイントは、少なくとも `text` または `media` のいずれかを含む JSON ボディを必要とします。

    ```json theme={null}
    {
      "text": "Hello from the X API!"
    }
    ```
  </Step>

  <Step title="リクエストを送信する">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{"text": "Hello from the X API!"}'
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # ポストを作成する
      response = client.posts.create(text="Hello from the X API!")
      print(f"Created Post: {response.data.id}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // ポストを作成する
      const response = await client.posts.create({ text: "Hello from the X API!" });
      console.log(`Created Post: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="レスポンスを確認する">
    正常なレスポンスには、新しいポストの `id` と `text` が含まれます。

    ```json theme={null}
    {
      "data": {
        "id": "1445880548472328192",
        "text": "Hello from the X API!"
      }
    }
    ```
  </Step>
</Steps>

***

<div id="advanced-examples">
  ## 高度な例
</div>

<AccordionGroup>
  <Accordion title="ポストに返信する">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "これは返信です！",
          "reply": {
            "in_reply_to_tweet_id": "1234567890"
          }
        }'
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # 返信を作成
      response = client.posts.create(
          text="これは返信です！",
          reply={"in_reply_to_tweet_id": "1234567890"}
      )
      print(f"返信を作成しました: {response.data.id}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // 返信を作成
      const response = await client.posts.create({
        text: "これは返信です！",
        reply: { inReplyToTweetId: "1234567890" },
      });
      console.log(`返信を作成しました: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="ポストを引用する">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "これ見て！",
          "quote_tweet_id": "1234567890"
        }'
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # ポストを引用する
      response = client.posts.create(
          text="これ見て！",
          quote_tweet_id="1234567890"
      )
      print(f"引用ポストを作成しました: {response.data.id}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // ポストを引用する
      const response = await client.posts.create({
        text: "これ見て！",
        quoteTweetId: "1234567890",
      });
      console.log(`引用ポストを作成しました: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="メディア付きポスト">
    まずは [Media Upload エンドポイント](/ja/x-api/media/quickstart/media-upload-chunked) を使ってメディアをアップロードし、その後に `media_id` を指定します。

    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "Photo of the day!",
          "media": {
            "media_ids": ["1234567890123456789"]
          }
        }'
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # メディア付きでポストする
      response = client.posts.create(
          text="Photo of the day!",
          media={"media_ids": ["1234567890123456789"]}
      )
      print(f"Created Post with media: {response.data.id}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // メディア付きでポストする
      const response = await client.posts.create({
        text: "Photo of the day!",
        media: { mediaIds: ["1234567890123456789"] },
      });
      console.log(`Created Post with media: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="投票付きポスト">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "あなたの好きな色は何ですか？",
          "poll": {
            "options": ["赤", "青", "緑", "黄色"],
            "duration_minutes": 1440
          }
        }'
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # 投票付きのポストを作成
      response = client.posts.create(
          text="あなたの好きな色は何ですか？",
          poll={"options": ["赤", "青", "緑", "黄色"], "duration_minutes": 1440}
      )
      print(f"Created poll: {response.data.id}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // 投票付きのポストを作成
      const response = await client.posts.create({
        text: "あなたの好きな色は何ですか？",
        poll: { options: ["赤", "青", "緑", "黄色"], durationMinutes: 1440 },
      });
      console.log(`Created poll: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

***

<div id="delete-a-post">
  ## ポストを削除する
</div>

<Steps>
  <Step title="ポストのIDを取得する">
    削除したいポストのIDが必要があります。これはポストの作成時に返されます。
  </Step>

  <Step title="DELETE リクエストを送信する">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X DELETE "https://api.x.com/2/tweets/1445880548472328192" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN"
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # ポストを削除する
      response = client.posts.delete("1445880548472328192")
      print(f"Deleted: {response.data.deleted}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // ポストを削除する
      const response = await client.posts.delete("1445880548472328192");
      console.log(`Deleted: ${response.data?.deleted}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="削除を確認する">
    ```json theme={null}
    {
      "data": {
        "deleted": true
      }
    }
    ```
  </Step>
</Steps>

<Warning>
  削除できるのは、あなたが作成した投稿だけです。
</Warning>

***

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

<CardGroup cols={2}>
  <Card title="連携ガイド" icon="book" href="/ja/x-api/posts/manage-tweets/integrate">
    基本概念とベストプラクティス
  </Card>

  <Card title="メディアアップロード" icon="image" href="/ja/x-api/media/quickstart/media-upload-chunked">
    投稿用メディアをアップロード
  </Card>

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

  <Card title="サンプルコード" icon="github" href="https://github.com/xdevplatform/Twitter-API-v2-sample-code">
    実行可能なコード例
  </Card>
</CardGroup>
