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

# Manage Bookmarks

> このガイドでは、X API を使用してブックマークを追加および削除する方法を説明します。クイックスタートを扱う X API v2 スタンダードティアのリファレンス。

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

このガイドでは、X API を使用してブックマークを追加および削除する方法を説明します。

<Note>
  **前提条件**

  始める前に以下が必要です:

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

***

## ブックマークを追加する

<Steps>
  <Step title="ユーザー ID を取得する">
    認証済みユーザーの ID が必要です。`/2/users/me` エンドポイントまたは[ユーザールックアップエンドポイント](/x-api/users/lookup/introduction)で確認できます。
  </Step>

  <Step title="投稿 ID を取得する">
    投稿を表示している URL から投稿 ID を見つけます:

    ```
    https://x.com/XDevelopers/status/1460323737035677698
                                    └── これが投稿 ID
    ```
  </Step>

  <Step title="ブックマークを追加する">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/users/2244994945/bookmarks" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{"tweet_id": "1460323737035677698"}'
      ```

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

      client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

      # ブックマークを追加
      response = client.bookmarks.create(
          user_id="2244994945",
          tweet_id="1460323737035677698"
      )

      print(f"Bookmarked: {response.data.bookmarked}")
      ```

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

      const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });

      // ブックマークを追加
      const response = await client.bookmarks.create("2244994945", {
        tweetId: "1460323737035677698",
      });

      console.log(`Bookmarked: ${response.data?.bookmarked}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="レスポンスを確認する">
    ```json theme={null}
    {
      "data": {
        "bookmarked": true
      }
    }
    ```
  </Step>
</Steps>

***

## ブックマークを削除する

投稿をブックマークから削除します:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.x.com/2/users/2244994945/bookmarks/1460323737035677698" \
    -H "Authorization: Bearer $USER_ACCESS_TOKEN"
  ```

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

  client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

  # ブックマークを削除
  response = client.bookmarks.delete(
      user_id="2244994945",
      tweet_id="1460323737035677698"
  )

  print(f"Bookmarked: {response.data.bookmarked}")
  ```

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

  const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });

  // ブックマークを削除
  const response = await client.bookmarks.delete("2244994945", "1460323737035677698");

  console.log(`Bookmarked: ${response.data?.bookmarked}`);
  ```
</CodeGroup>

**レスポンス:**

```json theme={null}
{
  "data": {
    "bookmarked": false
  }
}
```

***

## 必要なスコープ

OAuth 2.0 PKCE を使用する場合、アクセストークンには以下のスコープが必要です:

| Scope            | Description  |
| :--------------- | :----------- |
| `bookmark.write` | ブックマークの追加と削除 |
| `tweet.read`     | 投稿データを読み取り   |
| `users.read`     | ユーザーデータを読み取り |

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="ブックマークルックアップ" icon="bookmark" href="/x-api/posts/bookmarks/quickstart/bookmarks-lookup">
    ブックマークした投稿を取得
  </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/users/create-bookmark" width="24" height="24" data-path="icons/xds/icon-code.svg">
    エンドポイントの完全なドキュメント
  </Card>
</CardGroup>
