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

# Bookmarks Lookup

> このガイドでは、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.read` スコープを持つユーザーアクセストークン(OAuth 2.0 PKCE)
</Note>

***

## ブックマークを取得する

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

  <Step title="ブックマークをリクエストする">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/users/2244994945/bookmarks?\
      tweet.fields=created_at,public_metrics,author_id&\
      max_results=10" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN"
      ```

      ```python title="Python SDK" lines wrap icon="python" theme={null}
      from xdk import Client

      client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

      # ページネーションでブックマークした投稿を取得
      for page in client.bookmarks.get(
          "2244994945",
          tweet_fields=["created_at", "public_metrics", "author_id"],
          max_results=10
      ):
          for post in page.data:
              print(f"{post.text[:50]}... - Likes: {post.public_metrics.like_count}")
      ```

      ```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
      import { Client } from "@xdevplatform/xdk";

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

      // ページネーションでブックマークした投稿を取得
      const paginator = client.bookmarks.get("2244994945", {
        tweetFields: ["created_at", "public_metrics", "author_id"],
        maxResults: 10,
      });

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

  <Step title="レスポンスを確認する">
    ```json theme={null}
    {
      "data": [
        {
          "id": "1501258597237342208",
          "text": "Have you built a project using the X API you'd like to share with the community? We'd love to hear from you!",
          "created_at": "2024-01-15T10:30:00.000Z",
          "author_id": "2244994945",
          "public_metrics": {
            "retweet_count": 15,
            "reply_count": 8,
            "like_count": 89,
            "quote_count": 3
          }
        },
        {
          "id": "1501258542258348032",
          "text": "This is just one way developer innovation helps make X a better place...",
          "created_at": "2024-01-15T09:15:00.000Z",
          "author_id": "2244994945",
          "public_metrics": {
            "retweet_count": 22,
            "reply_count": 5,
            "like_count": 156,
            "quote_count": 7
          }
        }
      ],
      "meta": {
        "result_count": 2,
        "next_token": "7140dibdnow9c7btw4539n0vybdnx19ylpayqf16fjt4l"
      }
    }
    ```
  </Step>
</Steps>

***

## 投稿者情報を含める

expansions を使用して投稿の作者データを取得します:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/users/2244994945/bookmarks?\
  tweet.fields=created_at,author_id&\
  expansions=author_id&\
  user.fields=username,verified" \
    -H "Authorization: Bearer $USER_ACCESS_TOKEN"
  ```

  ```python title="Python SDK" lines wrap icon="python" theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

  # 作者情報付きでブックマークを取得
  for page in client.bookmarks.get(
      "2244994945",
      tweet_fields=["created_at", "author_id"],
      expansions=["author_id"],
      user_fields=["username", "verified"]
  ):
      for post in page.data:
          print(f"{post.text[:50]}...")
      # 作者情報は page.includes.users にあります
  ```

  ```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
  import { Client } from "@xdevplatform/xdk";

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

  // 作者情報付きでブックマークを取得
  const paginator = client.bookmarks.get("2244994945", {
    tweetFields: ["created_at", "author_id"],
    expansions: ["author_id"],
    userFields: ["username", "verified"],
  });

  for await (const page of paginator) {
    page.data?.forEach((post) => {
      console.log(`${post.text?.slice(0, 50)}...`);
    });
    // 作者情報は page.includes?.users にあります
  }
  ```
</CodeGroup>

***

## 必要なスコープ

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

| Scope           | Description                |
| :-------------- | :------------------------- |
| `bookmark.read` | ブックマークを読み取り                |
| `tweet.read`    | 投稿データを読み取り                 |
| `users.read`    | ユーザーデータを読み取り(expansions 用) |

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="ブックマークを管理" icon="bookmark" href="/x-api/posts/bookmarks/quickstart/manage-bookmarks">
    ブックマークの追加と削除
  </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/get-bookmarks" width="24" height="24" data-path="icons/xds/icon-code.svg">
    エンドポイントの完全なドキュメント
  </Card>
</CardGroup>
