> ## 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 Pinned Lists

> X API v2 の pinned Lists エンドポイントを利用して、認証済みユーザーのアカウントで X の List のピン留めおよびピン留め解除を行うクイックスタート。リクエスト例を含みます。

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

このガイドでは、List のピン留めおよびピン留め解除の手順を説明します。

<Note>
  **前提条件**

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

  * 承認済みの App がある [developer account](https://developer.x.com/en/portal/petition/essential/basic-info)
  * ユーザー Access Token (OAuth 1.0a または OAuth 2.0 PKCE)
</Note>

***

## List をピン留め

<Steps>
  <Step title="user ID と List ID を取得">
    認証済みユーザーの ID と、ピン留めしたい List の ID が必要です。List ID は List 表示時の URL で確認できます。
  </Step>

  <Step title="List をピン留め">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/users/2244994945/pinned_lists" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{"list_id": "1454155907651158017"}'
      ```

      ```python title="Python SDK" lines wrap icon="python" 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)

      # List をピン留め
      response = client.lists.pin(
          user_id="2244994945",
          list_id="1454155907651158017"
      )

      print(f"Pinned: {response.data.pinned}")
      ```

      ```javascript title="JavaScript SDK" lines wrap icon="square-js" 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 });

      // List をピン留め
      const response = await client.lists.pin("2244994945", {
        listId: "1454155907651158017",
      });

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

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

***

## List のピン留めを解除

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

  ```python title="Python SDK" lines wrap icon="python" 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)

  # List のピン留めを解除
  response = client.lists.unpin(
      user_id="2244994945",
      list_id="1454155907651158017"
  )

  print(f"Pinned: {response.data.pinned}")
  ```

  ```javascript title="JavaScript SDK" lines wrap icon="square-js" 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 });

  // List のピン留めを解除
  const response = await client.lists.unpin("2244994945", "1454155907651158017");

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

**レスポンス:**

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

***

## 重要なポイント

<Note>
  * ピン留めできるのは、フォローしているか自分が所有する List に限られます
  * ピン留めした List は X アプリの List の最上部に表示されます
  * ピン留めできる List の数には上限があります
</Note>

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="Pinned Lists lookup" icon="thumbtack" href="/x-api/lists/pinned-lists/quickstart/pinned-list-lookup">
    ピン留めした List を取得
  </Card>

  <Card title="List lookup" icon="https://mintcdn.com/x-preview/ygI6sSJPehlc0qNT/icons/xds/icon-bulleted-list.svg?fit=max&auto=format&n=ygI6sSJPehlc0qNT&q=85&s=b9bf8323233df59c682b0fec8e3f88d5" href="/x-api/lists/list-lookup/quickstart" width="24" height="24" data-path="icons/xds/icon-bulleted-list.svg">
    List の詳細を取得
  </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/lists/pin-list" width="24" height="24" data-path="icons/xds/icon-code.svg">
    エンドポイントの詳細ドキュメント
  </Card>
</CardGroup>
