> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Comments API 概要

> ソーシャル投稿へのコメントの投稿、返信、取得、削除を行います

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

<PlansAvailable plans={["premium"]} maxPackRequired={false} />

Comments エンドポイントを使用すると、ユーザーは自身の投稿に対してコメントの投稿、返信、取得、削除を行えます。
コメント ID には 4 種類あります: Ayrshare Post ID、Social Post ID、Ayrshare Comment ID、Social Comment ID。
それぞれの ID は目的に応じて使い分けます。

## コメント ID の種類

### Ayrshare Post ID を使用したコメント

一般的なフローは、Ayrshare 経由で投稿を公開すると Ayrshare Post ID が返される、というものです。
この [Ayrshare Post ID](/apis/overview#ayrshare-post-id) を使って、その投稿へのコメントを管理できます。

対応プラットフォーム: Bluesky、Facebook Pages、Instagram、LinkedIn、Reddit、Threads、TikTok、Twitter、YouTube。

例：

<Steps>
  <Step title="投稿を公開">
    [/post](/apis/post/post) エンドポイントで Ayrshare 経由で投稿を公開します。1 回の呼び出しで複数のソーシャルネットワークに送信できます。

    レスポンスのトップレベルに [Ayrshare Post ID](/apis/overview#ayrshare-post-id) が含まれます。

    ```json {12} theme={"system"}
    {
        "status": "success",
        "errors": [],
        "postIds": [
        {
            "status": "success",
            "id": "106638148652329_591370753547555",
            "postUrl": "https://www.facebook.com/106638148652329/posts/591370753547555",
            "platform": "facebook"
        }
        ],
        "id": "E4UdUr1yRbvI7qqCSlaq", // Ayrshare Post ID
        "refId": "9abf1426d6ce9122ef11c72bd62e59807c5cc055",
        "post": "What an amazing day",
        "validate": true
    }
    ```
  </Step>

  <Step title="コメントを投稿">
    [/comments](/apis/comments/post-comment) エンドポイントに Ayrshare Post ID を渡してコメントを投稿します。
    コメントは元投稿が公開されたすべてのソーシャルネットワークに自動的に投稿されます。
    たとえば、Facebook と Instagram に投稿していれば、コメントは両方のプラットフォームに表示されます。

    ```http theme={"system"}
    POST https://api.ayrshare.com/api/comments/:id
    ```
  </Step>

  <Step title="コメントを取得">
    [/comments](/apis/comments/get-comments) エンドポイントに Ayrshare Post ID を渡すことで、投稿のコメントを取得できます。
    投稿が公開されたすべてのソーシャルネットワークからコメントが返されます。
    たとえば、Facebook と Instagram に投稿していれば、両方のプラットフォームからコメントを取得できます。

    ```http theme={"system"}
    GET https://api.ayrshare.com/api/comments/:id
    ```
  </Step>
</Steps>

### Social Post ID を使用したコメント

Ayrshare 経由で公開されていない投稿のコメントを管理したい場合があります。
その場合は [Social Post ID](/apis/overview#social-post-id)（ソーシャルネットワークが割り当てた投稿 ID）を使用します。

<Note>
  Ayrshare 経由で公開された投稿の場合は [Ayrshare Post ID](/apis/comments/overview#comments-with-ayrshare-post-id) を使用してください。
</Note>

例：

<Steps>
  <Step title="投稿履歴を取得">
    まず、[Get All Post History エンドポイント](/apis/history/history-platform) を使って、Ayrshare 経由以外で公開された Instagram 投稿を取得します。

    エンドポイントは投稿のソーシャル `id` を含む投稿リストを返します。

    ```json {13} theme={"system"}
    {
        "status": "success",
        "posts": [
            {
                "mediaUrl": "https://scontent.cdninstagram.com/v/t51.2885-15/7531.jpg",
                "permalink": "https://www.instagram.com/p/B5OBT3ygpfg/",
                "commentsCount": 0,
                "created": "2022-05-20T17:26:03Z",
                "likeCount": 0,
                "mediaProductType": "FEED",
                "mediaType": "IMAGE",
                "username": "thegoodone",
                "id": "17833140557332933", // Instagram Social Post ID
                "thumbnailUrl": "https://scontent-lga3-2.cdninstagram.com/v/t51..jpg",
                "post": "The #Mandalorian is on tonight instead of Friday",
                "postUrl": "https://www.instagram.com/p/B5OBT3ygpfg/"
            },
        ]
    }
    ```

    <Note>ソーシャル投稿 `id` は [post エンドポイント](/apis/post/post) の `postIds` フィールドでも返されます。</Note>
  </Step>

  <Step title="投稿のコメントを取得">
    返された `id` を使い、ソーシャル `id`、`searchPlatformId` を `true`、`platform` を `instagram` に設定して、特定の Instagram 投稿の[すべてのコメントを取得](/apis/comments/get-comments) します。

    ```http theme={"system"}
    GET https://api.ayrshare.com/api/comments/17833140557332933?platform=instagram&searchPlatformId=true
    ```
  </Step>

  <Step title="コメント ID を使ってコメント詳細を取得">
    前の手順で返される JSON には、各コメントの [Social Comment ID](/apis/overview#social-comment-id) である `commentId` が含まれます。

    ```json {5} theme={"system"}
    {
        "instagram": [
            {
                "comment": "What an amazing comment",
                "commentId": "17969247335804735", // Social Comment ID
                "created": "2024-11-26T11:49:00Z",
                "from": {
                "id": "103038435208332",
                "username": "john_smith"
                },
                "hidden": false,
                "likeCount": 3,
                "platform": "instagram",
                "postId": "18231730279304333",
                "username": "john_smith"
            }
        ]
    }

    ```
  </Step>
</Steps>

### Ayrshare Comment ID を使用したコメント

Ayrshare 経由で公開された投稿のコメントを [Ayrshare Comment ID](/apis/overview#ayrshare-comment-id) を使って管理します。
Ayrshare comment ID は Ayrshare から割り当てられたコメント ID で、[コメント投稿](/apis/comments/post-comment) レスポンスの `commentId` フィールドから取得できます。

これは Ayrshare 経由で公開された特定のコメントの詳細を取得したい場合によく使われます。

### Social Comment ID を使用したコメント

Ayrshare 経由で公開されていない投稿のコメントを [Social Comment ID](/apis/overview#social-comment-id) を使って管理します。
Social Comment ID はソーシャルネットワークから割り当てられたコメント ID であり Ayrshare の ID ではなく、[コメント取得](/apis/comments/get-comments) レスポンスの `commentId` フィールドから取得できます。

```http theme={"system"}
GET https://api.ayrshare.com/api/comments/17969247335804735?platform=instagram&searchPlatformId=true&commentId=true
```

これは、LinkedIn でのコメントへの返信のように、Ayrshare 外で公開された特定のコメントの詳細を取得したい場合によく使われます。

## コメントの無効化

[/post エンドポイント](/apis/post/post) の `disableComments` フィールドを使って、投稿公開時にコメントを無効化できます。コメントが無効化されるのは Instagram、LinkedIn、TikTok のみです。

すでに公開された投稿については、[update post](/apis/post/update-post) エンドポイントと `disableComments` フィールドを使って、コメントの有効化・無効化を切り替えることもできます。

## プラットフォーム制限

<Note>
  **TikTok — `DELETE /comments` は自作コメントのみ。** TikTok の [`DELETE /comments`](/apis/comments/delete-comments) は、認証済み TikTok アカウント自身が投稿したコメント（自身の返信）に対してのみ成功します。他のユーザーが投稿したコメントを削除しようとすると Ayrshare `code: 328` が返されます。自身の TikTok 動画上の第三者コメントを管理する必要がある場合は、連携アカウントタイプで何が利用可能かをサポートで確認してください。
</Note>

```
```
