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

# ユーザーメンションタイムライン

> 特定のユーザーに対するメンションを含む投稿を取得する

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

このガイドでは、特定のユーザーがメンションされている投稿を取得する方法を説明します。

<Note>
  **前提条件**

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

  * 承認済みの App を持つ[開発者アカウント](https://developer.x.com/en/portal/petition/essential/basic-info)
  * App のベアラートークン (公開データ用) またはユーザーアクセストークン (非公開のメトリクス用)
</Note>

***

<div id="get-user-mentions">
  ## ユーザーへのメンションを取得する
</div>

<Steps>
  <Step title="ユーザーIDを取得する">
    [ユーザー照会エンドポイント](/ja/x-api/users/lookup/introduction)を使ってユーザーIDを特定します。たとえば、@XDevelopers のユーザーIDは `2244994945` です。
  </Step>

  <Step title="メンションタイムラインをリクエストする">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/users/2244994945/mentions?\
      tweet.fields=created_at,public_metrics,author_id&\
      expansions=author_id&\
      user.fields=username,verified&\
      max_results=10" \
        -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.get_user_mentions(
          "2244994945",
          tweet_fields=["created_at", "public_metrics", "author_id"],
          expansions=["author_id"],
          user_fields=["username", "verified"],
          max_results=10
      ):
          for post in page.data:
              print(f"@{post.author_id}: {post.text[:50]}...")
      ```

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

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

      // ページネーション付きでメンションタイムラインを取得
      const paginator = client.posts.getUserMentions("2244994945", {
        tweetFields: ["created_at", "public_metrics", "author_id"],
        expansions: ["author_id"],
        userFields: ["username", "verified"],
        maxResults: 10,
      });

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

  <Step title="レスポンスを確認する">
    ```json theme={null}
    {
      "data": [
        {
          "id": "1301573587187331074",
          "text": "Hey @XDevelopers、新しい API がとても気に入っています！",
          "author_id": "1234567890",
          "created_at": "2024-01-15T10:30:00.000Z",
          "public_metrics": {
            "retweet_count": 5,
            "reply_count": 2,
            "like_count": 42,
            "quote_count": 1
          }
        }
      ],
      "includes": {
        "users": [
          {
            "id": "1234567890",
            "username": "developer",
            "name": "Dev Person",
            "verified": false
          }
        ]
      },
      "meta": {
        "newest_id": "1301573587187331074",
        "oldest_id": "1301573587187331074",
        "result_count": 1,
        "next_token": "t3buvdr5pujq9g7bggsnf3ep2ha28"
      }
    }
    ```
  </Step>
</Steps>

***

<div id="filter-mentions">
  ## メンションをフィルタリングする
</div>

<div id="exclude-replies">
  ### 返信を除外する
</div>

ユーザーへのメンションのうち、返信ではない元のポストのみを取得します:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/users/2244994945/mentions?\
  exclude=replies&\
  max_results=10" \
    -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.get_user_mentions(
      "2244994945",
      exclude=["replies"],
      max_results=10
  ):
      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.getUserMentions("2244994945", {
    exclude: ["replies"],
    maxResults: 10,
  });

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

<div id="get-mentions-in-a-time-range">
  ### 特定の期間内のメンションを取得
</div>

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/users/2244994945/mentions?\
  start_time=2024-01-01T00%3A00%3A00Z&\
  end_time=2024-01-31T23%3A59%3A59Z" \
    -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.get_user_mentions(
      "2244994945",
      start_time="2024-01-01T00:00:00Z",
      end_time="2024-01-31T23:59:59Z"
  ):
      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" });

  // 特定の期間内のメンションを取得
  const paginator = client.posts.getUserMentions("2244994945", {
    startTime: "2024-01-01T00:00:00Z",
    endTime: "2024-01-31T23:59:59Z",
  });

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

***

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

| パラメーター             | 説明                              | デフォルト |
| :----------------- | :------------------------------ | :---- |
| `max_results`      | 1 ページあたりの結果数 (1-100)            | 10    |
| `start_time`       | 最も古いポストのタイムスタンプ (ISO 8601)      | —     |
| `end_time`         | 最も新しいポストのタイムスタンプ (ISO 8601)     | —     |
| `since_id`         | この ID 以降の投稿を返す                  | —     |
| `until_id`         | この ID 以前の投稿を返す                  | —     |
| `exclude`          | `retweets`、`replies`、またはその両方を除外 | —     |
| `pagination_token` | 次ページ用のトークン                      | —     |

***

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

<CardGroup cols={2}>
  <Card title="ホームタイムライン" icon="house" href="/ja/x-api/posts/timelines/quickstart/reverse-chron-quickstart">
    ユーザーのホームタイムラインを取得する
  </Card>

  <Card title="インテグレーションガイド" icon="book" href="/ja/x-api/posts/timelines/integrate">
    基本概念とベストプラクティスを理解する
  </Card>

  <Card title="APIリファレンス" icon="code" href="/ja/x-api/posts/user-mention-timeline-by-user-id">
    エンドポイントの完全なドキュメントを確認する
  </Card>

  <Card title="ページネーションガイド" icon="arrow-right" href="/ja/x-api/fundamentals/pagination">
    大規模な結果セットを扱う
  </Card>
</CardGroup>
