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

# v1 から v2 への移行

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

<div id="manage-follows-standard-v11-compared-to-x-api-v2">
  #### フォローの管理: Standard v1.1 と X API v2 の比較
</div>

Standard v1.1 の [POST friendships/create](https://developer.x.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create) および [POST friendships/destroy](https://developer.x.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-destroy) エンドポイントを利用している場合、このガイドは、Standard と X API v2 のフォロー管理エンドポイントの共通点と相違点を理解するのに役立つことを目的としています。

* **共通点**
  * OAuth 1.0a の User Context
* **相違点**
  * エンドポイント URL
  * App と Project の要件
  * HTTP メソッド
  * リクエストパラメータ

<div id="similarities">
  #### 類似点
</div>

**OAuth 1.0a User Context 認証方式**

両方のエンドポイントのバージョンは [OAuth 1.0a User Context](/ja/resources/fundamentals/authentication#oauth-1-0a-2) をサポートしています。したがって、以前に標準の v1.1 のフォロー管理エンドポイントのいずれかを使用していた場合、X API v2 版へ移行しても、同じ認証方式を引き続き使用できます。

<div id="differences">
  #### 相違点
</div>

**エンドポイント URL**

* Standard v1.1 エンドポイント:
  * POST [https://api.x.com/1.1/friendships/create.json](https://api.x.com/1.1/friendships/create.json)
    (ユーザーをフォロー)
  * POST [https://api.x.com/1.1/friendships/destroy.json](https://api.x.com/1.1/friendships/destroy.json)
    (ユーザーのフォローを解除)
* X API v2 エンドポイント:
  * POST [https://api.x.com/2/users/:id/following](https://api.x.com/2/users/:id/following)
    (ユーザーをフォロー)
  * DELETE [https://api.x.com/2/users/:source\&#95;user\&#95;id/following/:target\&#95;user\&#95;id](https://api.x.com/2/users/:source\&#95;user\&#95;id/following/:target\&#95;user\&#95;id)
    (ユーザーのフォローを解除)

**App と Project の要件**

X API v2 のエンドポイントでは、リクエストを認証する際に、[developer App](/ja/resources/fundamentals/developer-apps) と、それに関連付けられた [Project](/ja/resources/fundamentals/developer-apps) の認証情報を使用する必要があります。X API v1.1 のすべてのエンドポイントでは、個別の App からの認証情報、または Project に関連付けられた App からの認証情報を使用できます。

**リクエストパラメータ**

次の Standard v1.1 のリクエストパラメータには、X API v2 における対応パラメータがあります:

| Standard v1.1 | X API v2                             |
| :------------ | :----------------------------------- |
| 対応なし          | id (POST), source\_user\_id (DELETE) |
| user\_id      | target\_user\_id                     |
| screen\_name  | 対応なし                                 |

Standard v1.1 のパラメータはクエリパラメータとして渡される一方で、X API v2 のパラメータはボディパラメータ (POST エンドポイントの場合) またはパスパラメータ (DELETE エンドポイントの場合) として渡される点に注意してください。

また、Standard v1.1 エンドポイントを使用する場合、OAuth 1.0a User Context で渡される Access Tokens によってフォロー/フォロー解除を開始したユーザーが推論されるため、v2 の id および source\_user\_id は必須ではありません。

***

<div id="code-examples">
  ## コードサンプル
</div>

<div id="follow-a-user-v2">
  ### ユーザーをフォローする (v2)
</div>

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl -X POST "https://api.x.com/2/users/123456789/following" \
    -H "Authorization: OAuth ..." \
    -H "Content-Type: application/json" \
    -d '{"target_user_id": "2244994945"}'
  ```

  ```python Python theme={null}
  # OAuth 1.0a のユーザーコンテキスト認証が必要です
  import requests
  from requests_oauthlib import OAuth1

  auth = OAuth1(
      "API_KEY", "API_SECRET",
      "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET"
  )

  url = "https://api.x.com/2/users/123456789/following"
  response = requests.post(url, auth=auth, json={"target_user_id": "2244994945"})
  print(response.json())
  ```

  ```python Python SDK 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)

  # ユーザーをフォローする
  response = client.users.follow(
      source_user_id="123456789",
      target_user_id="2244994945"
  )
  print(f"Following: {response.data.following}")
  ```

  ```javascript JavaScript SDK 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 });

  // ユーザーをフォローする
  const response = await client.users.follow("123456789", {
    targetUserId: "2244994945",
  });
  console.log(`Following: ${response.data?.following}`);
  ```
</CodeGroup>

<div id="unfollow-a-user-v2">
  ### ユーザーのフォローを解除する (v2)
</div>

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.x.com/2/users/123456789/following/2244994945" \
    -H "Authorization: OAuth ..."
  ```

  ```python Python theme={null}
  # OAuth 1.0a のユーザーコンテキスト認証が必要です
  import requests
  from requests_oauthlib import OAuth1

  auth = OAuth1(
      "API_KEY", "API_SECRET",
      "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET"
  )

  url = "https://api.x.com/2/users/123456789/following/2244994945"
  response = requests.delete(url, auth=auth)
  print(response.json())
  ```

  ```python Python SDK 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)

  # ユーザーのフォローを解除する
  response = client.users.unfollow(
      source_user_id="123456789",
      target_user_id="2244994945"
  )
  print(f"Following: {response.data.following}")
  ```

  ```javascript JavaScript SDK 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 });

  // ユーザーのフォローを解除する
  const response = await client.users.unfollow("123456789", "2244994945");
  console.log(`Following: ${response.data?.following}`);
  ```
</CodeGroup>
