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

# Retweets Lookup

> このガイドでは、特定の投稿を Retweet したユーザーの取得方法を説明します。クイックスタートを扱う 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>;
};

このガイドでは、特定の投稿を Retweet したユーザーの取得方法を説明します。

<Note>
  **前提条件**

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

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

***

## 投稿を Retweet したユーザーを取得する

<Steps>
  <Step title="投稿 ID を見つける">
    Retweet を検索したい投稿の ID を取得します:

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

  <Step title="リクエストを実行する">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/tweets/1354143047324299264/retweeted_by?\
      user.fields=created_at,username,verified" \
        -H "Authorization: Bearer $BEARER_TOKEN"
      ```

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

      client = Client(bearer_token="YOUR_BEARER_TOKEN")

      # ページネーションで投稿を Retweet したユーザーを取得
      for page in client.posts.get_retweeted_by(
          "1354143047324299264",
          user_fields=["created_at", "username", "verified"]
      ):
          for user in page.data:
              print(f"{user.username} - Joined: {user.created_at}")
      ```

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

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

      // ページネーションで投稿を Retweet したユーザーを取得
      const paginator = client.posts.getRetweetedBy("1354143047324299264", {
        userFields: ["created_at", "username", "verified"],
      });

      for await (const page of paginator) {
        page.data?.forEach((user) => {
          console.log(`${user.username} - Joined: ${user.created_at}`);
        });
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="レスポンスを確認する">
    ```json theme={null}
    {
      "data": [
        {
          "created_at": "2008-12-04T18:51:57.000Z",
          "id": "17874544",
          "username": "TwitterSupport",
          "name": "Twitter Support",
          "verified": true
        },
        {
          "created_at": "2007-02-20T14:35:54.000Z",
          "id": "783214",
          "username": "Twitter",
          "name": "Twitter",
          "verified": true
        }
      ],
      "meta": {
        "result_count": 2,
        "next_token": "7140dibdnow9c7btw3z2vwioavpvutgzrzm9icis4ndix"
      }
    }
    ```
  </Step>
</Steps>

***

## 追加データを含める

expansions を使用して固定投稿などの関連データを取得します:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/tweets/1354143047324299264/retweeted_by?\
  user.fields=created_at&\
  expansions=pinned_tweet_id&\
  tweet.fields=created_at" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

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

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # expansions 付きで Retweet したユーザーを取得
  for page in client.posts.get_retweeted_by(
      "1354143047324299264",
      user_fields=["created_at"],
      expansions=["pinned_tweet_id"],
      tweet_fields=["created_at"]
  ):
      for user in page.data:
          print(f"{user.username}")
      # 固定投稿は page.includes.tweets にあります
  ```

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

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

  // expansions 付きで Retweet したユーザーを取得
  const paginator = client.posts.getRetweetedBy("1354143047324299264", {
    userFields: ["created_at"],
    expansions: ["pinned_tweet_id"],
    tweetFields: ["created_at"],
  });

  for await (const page of paginator) {
    page.data?.forEach((user) => {
      console.log(user.username);
    });
    // 固定投稿は page.includes?.tweets にあります
  }
  ```
</CodeGroup>

### expansion 付きのレスポンス

```json title="レスポンス例" lines wrap icon="https://mintcdn.com/x-preview/Vn2KEkZaPF9LiPi3/icons/xds/icon-brackets.svg?fit=max&auto=format&n=Vn2KEkZaPF9LiPi3&q=85&s=ed2428e77bab43e57800e1a590e982fa" theme={null}
{
  "data": [
    {
      "pinned_tweet_id": "1389270063807598594",
      "created_at": "2018-11-21T14:24:58.000Z",
      "id": "1065249714214457345",
      "username": "TwitterSpaces",
      "name": "Spaces"
    }
  ],
  "includes": {
    "tweets": [
      {
        "created_at": "2021-05-03T17:26:09.000Z",
        "id": "1389270063807598594",
        "text": "now, everyone with 600 or more followers can host a Space..."
      }
    ]
  }
}
```

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="Manage Retweets" icon="retweet" href="/x-api/posts/retweets/quickstart/manage-retweets">
    Retweet と取り消し
  </Card>

  <Card title="Quote Posts" icon="quote-left" href="/x-api/posts/quote-tweets/quickstart">
    引用投稿を取得
  </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/posts/get-reposted-by" width="24" height="24" data-path="icons/xds/icon-code.svg">
    エンドポイントの完全なドキュメント
  </Card>
</CardGroup>
