> ## 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 類型：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 發布貼文，可在單一呼叫中傳送到多個社群網路。

    回傳的最外層即為 [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)，也就是社群網路指派的 post ID。

<Note>
  若該貼文是透過 Ayrshare 發布，請改用 [Ayrshare Post ID](/apis/comments/overview#comments-with-ayrshare-post-id)。
</Note>

例如：

<Steps>
  <Step title="取得貼文歷史">
    首先透過[取得全部貼文歷史端點](/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>社群 post `id` 也會回傳在 [post 端點](/apis/post/post)的 `postIds` 欄位中。</Note>
  </Step>

  <Step title="取得貼文的留言">
    使用取得的 `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="使用 Comment ID 取得留言詳情">
    前一步驟回傳的 JSON 中，每則留言都有一個 `commentId`，即 [social comment ID](/apis/overview#social-comment-id)。

    ```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 Comment ID](/apis/overview#ayrshare-comment-id) 管理透過 Ayrshare 發布的貼文之留言。
Ayrshare comment ID 是由 Ayrshare 指派的留言 ID，可在[發布留言](/apis/comments/post-comment)的回應中的 `commentId` 欄位找到。

若你想取得某則透過 Ayrshare 發布之留言的詳情，通常會使用此 ID。

### 使用 Social Comment ID 管理留言

使用 [Social Comment ID](/apis/overview#social-comment-id) 管理非透過 Ayrshare 發布的貼文之留言。
Social comment ID 是來自社群網路的 comment 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
```

若你想取得某則非透過 Ayrshare 發布之留言的詳情（例如 LinkedIn 對留言的回覆），通常會使用此 ID。

## 停用留言

發布貼文時可透過 [/post 端點](/apis/post/post) 的 `disableComments` 欄位停用留言。留言僅會在 Instagram、LinkedIn 與 TikTok 上被停用。

你也可以在已發布的貼文上，透過[更新貼文](/apis/post/update-post)端點與 `disableComments` 欄位，啟用或停用留言。

## 平台限制

<Note>
  **TikTok — `DELETE /comments` 僅限自己撰寫的留言。** [`DELETE /comments`](/apis/comments/delete-comments) 在 TikTok 上僅對已認證 TikTok 帳號本身所撰寫的留言（即你自己的回覆）成功。嘗試刪除其他使用者所撰寫的留言會回傳 Ayrshare `code: 328`。若你需要審核自己 TikTok 影片下的第三方留言，請聯絡支援，讓我們確認你所連結的帳號類型上有哪些可用選項。
</Note>

```
```
