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

# Ayrshare API 概觀

> 強大的社群 API，讓你輕鬆發送社群媒體貼文並取得分析資料。適用於各種規模的開發者與企業。

Social Media REST API 讓開發者能透過單一整合介面以程式化方式存取多個社群網路。
透過 Ayrshare 的 social API，你可以管理各項社群媒體活動，包含建立與刪除貼文、取得分析資料、處理留言與評論、管理私訊（DM）、建立 Facebook 廣告，以及跨平台執行其他社群媒體操作。

此 API 目前支援 13 個主要社群網路：Bluesky、Facebook、Google Business Profile、Instagram、LinkedIn、Pinterest、Reddit、Snapchat、Telegram、Threads、TikTok、X（前身為 Twitter）與 YouTube。
透過整合此 API，開發者可以同時自動化在所有這些平台上的社群媒體管理工作。

API 呼叫的請求與回應資料皆為 JSON 格式，方便在大多數程式語言中進行解析與處理。

如果你使用 Launch、Business 或 Enterprise Plan，請參閱 [Business Plan 概觀](/multiple-users/business-plan-overview)、[Launch Plan 概觀](/multiple-users/business-launch-overview) 與 [/profiles API 端點](/apis/profiles/overview)。

## 主要功能

<ul class="custom-bullets">
  <li>[支援 13 個社群網路](/introduction#which-social-networks-are-supported)。</li>
  <li>透過你專屬的 API Key 進行安全的 API 存取。</li>
  <li>可排程發布到已連結的社群媒體平台。</li>
  <li>依據預定的排程自動發布。</li>
  <li>支援圖片與影片內容，包含 Reels、Stories 與 Spotlight。</li>
  <li>刪除已連結社群網路上的貼文。</li>
  <li>完整的貼文互動分析（按讚、分享等）。</li>
  <li>社群帳號指標，包含追蹤者數量與人口統計資料。</li>
  <li>留言管理：檢視、新增與刪除貼文留言。</li>
  <li>可對貼文中所有或特定 URL 進行選擇性縮短網址。</li>
  <li>Unsplash 整合：加入指定圖片或依關鍵字隨機選取。</li>
  <li>使用相關關鍵字自動產生 hashtag 的選項。</li>
  <li>貼文歷史紀錄追蹤，包含非透過 Ayrshare 發布的貼文。</li>
  <li>評論管理：取得、回覆與刪除評論回應。</li>
  <li>RSS 動態整合，可自動化發布內容。</li>
  <li>媒體庫：上傳並儲存要用於貼文的照片與影片。</li>
  <li>[Social Post Verification System](/testing/post-verification) 讓你的社群帳號更安全。</li>
</ul>

## Business Plan 與 Launch Plan

[Business Plan](/multiple-users/business-plan-overview) 與 [Launch Plan](/multiple-users/business-launch-overview) 為管理多位使用者與客戶提供的功能：

<ul class="custom-bullets">
  <li>讓使用者可將自己的社群媒體帳號連結到你的平台。</li>
  <li>透過 OAuth 的安全單一登入，快速完成帳號連結。</li>
  <li>透過 API 以程式方式建立與移除 User Profile。</li>
  <li>存取進階使用者分析。</li>
  <li>支援即時更新的 webhook。</li>
  <li>在所支援的平台上進行私訊管理。</li>
  <li>從既有貼文建立 Facebook 廣告。</li>
</ul>

如需進一步了解 [Business Plan](https://www.ayrshare.com/business-plan-for-multiple-users/)，歡迎與我們聯絡。

## Ads API

[Ads API](/apis/ads/overview) 讓你可以從既有貼文建立 Facebook 廣告。

<ul class="custom-bullets">
  <li>加強貼文推廣觸及更多人。</li>
  <li>管理廣告並追蹤成效。</li>
  <li>分析廣告花費並優化投放策略。</li>
</ul>

<Card title="Ads API" icon="code" href="/apis/ads/overview" horizontal>
  探索 Ads API
</Card>

## Messages API

統一的 [Messaging API](/apis/messages/overview)，讓你可以在主要社群媒體管道（Facebook、Instagram 與 X）上與使用者進行對話。

<ul class="custom-bullets">
  <li>傳送文字、圖片與影片訊息。</li>
  <li>取得完整的對話歷史紀錄。</li>
  <li>設定自動化訊息回覆。</li>

  <li>
    透過 webhook 即時接收訊息接收、訊息表情回應以及已讀
    回條的更新。
  </li>
</ul>

此 API 將多個社群媒體管道的訊息操作集中管理，簡化與使用者互動的流程。了解更多…

<Card title="Messages API" icon="code" href="/apis/messages/overview" horizontal>
  探索統一的 messaging API
</Card>

## Max Pack

透過 [Max Pack 加購方案](/additional/maxpack) 取得更多功能：

<Card title="Max Pack" icon="link" href="/additional/maxpack" horizontal>
  透過我們的 Max Pack 加購方案，解鎖 AI 內容生成、強化分析與更廣泛的平台
  支援等進階功能。
</Card>

## 觀看 Social API 使用示範

如果你使用 Node.js 開發，可以觀看這支影片，了解如何連結並將貼文發布到 X 與 Facebook。

<div class="video-container">
  <iframe width="560" height="315" src="https://www.youtube.com/embed/OMtj2h6sW6U" title="How to Use Ayrshare's Social API" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" />
</div>

## Social API 示範

如果你使用 Node.js，可以參考 social API 示範程式碼，快速開始你自己的 social API 整合。

<Card title="Social API 示範" icon="github" href="https://github.com/ayrshare/social-api-demo" horizontal>
  探索我們的 Node.js 示範程式碼，快速啟動你的 social API 整合
</Card>

## Base URL

Ayrshare API 所有端點的 base URL 相同：

`https://api.ayrshare.com/api`

## 授權

Ayrshare 透過 HTTP header 中傳遞的 Authorization token 驗證 API 請求。請務必在 API Key 前加上 `Bearer`。你可以在 Ayrshare Dashboard 中切換到 Primary Profile 找到 API Key。

如果你是 Business 或 Enterprise 使用者，可以建立帶有 Profile Key 的 User Profile 來管理多位客戶。Profile Key 需放在請求的 header 中。
對於 User Profile 的請求，API Key 同樣必須放在 header 中。

<Tip>
  Premium 方案在請求 header 中應僅使用 API Key。Business 與 Enterprise
  方案在代表 User Profile 進行操作時，應在請求 header 中使用 Profile Key。
</Tip>

### API Key 格式

`Authorization: Bearer API_KEY`，將 API\_KEY 替換為你的 Primary Profile API Key，可以[在 Ayrshare Dashboard 中找到](/quickstart#get-your-api-key)。

<CodeGroup>
  ```bash cURL theme={"system"}
  curl -H "Authorization: Bearer API_KEY" \
       -X GET https://api.ayrshare.com/api
  ```

  ```javascript JavaScript theme={"system"}
  headers: {"Authorization": "Bearer API_KEY"}
  ```

  ```python Python theme={"system"}
  headers = {"Authorization": "Bearer API_KEY"}
  ```

  ```php PHP theme={"system"}
  $headers = ["Authorization" => "Bearer API_KEY"];
  ```

  ```go Go theme={"system"}
  headers := map[string]string{"Authorization": "Bearer API_KEY"}
  ```

  ```ruby Ruby theme={"system"}
  headers = {"Authorization": "Bearer API_KEY"}
  ```

  ```java Java theme={"system"}
  headers = {"Authorization": "Bearer API_KEY"}
  ```

  ```csharp C# theme={"system"}
  headers = {"Authorization": "Bearer API_KEY"}
  ```

  ```rust Rust theme={"system"}
  headers = {"Authorization": "Bearer API_KEY"}
  ```
</CodeGroup>

<Note>
  你的密鑰 API Key 可在 Ayrshare dashboard 中，左側導覽面板的 API Key 頁面取得。

  例如，如果你的 API Key 是 2MPXPKQ-S03M5LS-GR5RX5G-AZCK8EA

  你的 header 應包含：

  `Authorization: Bearer 2MPXPKQ-S03M5LS-GR5RX5G-AZCK8EA`
</Note>

### Profile Key 格式

Profile Key 用於代表 User Profile 進行操作。
此功能僅適用於 Business 或 Enterprise 方案。

`Profile-Key: PROFILE_KEY`，將 PROFILE\_KEY 替換為某使用者的 [Profile Key](/multiple-users/manage-user-profiles#get-the-profile-key)。

**若要代表 User Profile 進行操作，header 中必須包含 Profile Key**。

若缺少 Primary Profile API Key，或在 header 中以 Profile Key 取代 API Key，都會導致錯誤。

以下是如何為 API 請求組合這些 header：

<CodeGroup>
  ```bash cURL theme={"system"}
  curl -H "Authorization: Bearer API_KEY" \ 
       -H "Profile-Key: PROFILE_KEY" \
       -X GET https://api.ayrshare.com/api
  ```

  ```javascript JavaScript theme={"system"}
  headers: {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY"
  }
  ```

  ```python Python theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY"
  }
  ```

  ```php PHP theme={"system"}
  $headers = [
    "Authorization" => "Bearer API_KEY",
    "Profile-Key" => "PROFILE_KEY"
  ];
  ```

  ```go Go theme={"system"}
  headers := map[string]string{
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY"
  }
  ```

  ```ruby Ruby theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY"
  }
  ```

  ```java Java theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY"
  }
  ```

  ```csharp C# theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY"
  }
  ```

  ```rust Rust theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY"
  }
  ```
</CodeGroup>

<Note>
  可在 Ayrshare Dashboard 中左側導覽面板的 Profile Key 頁面[找到 Profile Key](/multiple-users/manage-user-profiles#get-the-profile-key)。
  先在 User Profile 頁面切換到你想使用的 Profile。
  此外，[Create a User Profile](/apis/profiles/create-profile) 端點的回應中也會回傳 Profile Key。

  之後便可以在請求的 header 中使用 Profile Key：

  例如，如果你的 Profile Key 是 `AX1XGG-9jK3M5LS-GR5RX5G-LLCK8EA`

  你的 header 應同時包含 API 與 Profile Key：

  `Authorization: Bearer 2MPXPKQ-S03M5LS-GR5RX5G-AZCK8EA`

  `Profile-Key: AX1XGG-9jK3M5LS-GR5RX5G-LLCK8EA`
</Note>

### X/Twitter BYO 憑證

自 2026 年 3 月 31 日起，所有透過 Ayrshare 進行的 X/Twitter 操作都需要你自己的 OAuth 1.0a 憑證。透過 OAuth 連結你的 X 帳號後，對於任何以 X/Twitter 為目標的請求，除了 `Authorization`（以及選填的 `Profile-Key`）header 外，還需一併傳入以下 2 個 header：

| Header                        | 說明                                            |
| ----------------------------- | --------------------------------------------- |
| `X-Twitter-OAuth1-Api-Key`    | 你的 OAuth 1.0a API Key（Consumer Key）           |
| `X-Twitter-OAuth1-Api-Secret` | 你的 OAuth 1.0a API Key Secret（Consumer Secret） |

自 2026 年 3 月 31 日起，這些 header 為必填。若未提供有效的 BYO 憑證，X/Twitter 端點的請求將被拒絕。

<Info>
  **一組金鑰組，用於每一個請求。** 你為每個 Ayrshare 帳號建立一個 X Developer App，並在每個以 X 為目標的請求中使用相同的 `X-Twitter-OAuth1-Api-Key` 與 `X-Twitter-OAuth1-Api-Secret` 值，不論該請求是針對哪個子 profile（`Profile-Key`）。你不需要為每位客戶或每位終端使用者產生或輪替金鑰。
</Info>

詳細的步驟、程式碼範例與疑難排解請參閱 [X BYO Key 設定指南](/dashboard/connect-social-accounts/x-twitter-byo-keys)。

透過 [MCP Server](/additional/mcp-action-server) 驅動 X/Twitter 時也適用同樣的兩個 header — 請參閱 [Connect & Setup](/additional/mcp-action-connect)。

## Content Type

除非端點另有指定，Content Type 應一律設為 `Content-Type: "application/json"`。

<CodeGroup>
  ```bash cURL theme={"system"}
  curl -H "Authorization: Bearer API_KEY" \ 
       -H "Profile-Key: PROFILE_KEY" \ # Optional
       -H "Content-Type: application/json" \
       -X GET https://api.ayrshare.com/api
  ```

  ```javascript JavaScript theme={"system"}
  headers: {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", // Optional
    "Content-Type": "application/json"
  }
  ```

  ```python Python theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", # Optional
    "Content-Type": "application/json"
  }
  ```

  ```php PHP theme={"system"}
  $headers = [
    "Authorization" => "Bearer API_KEY",
    "Profile-Key" => "PROFILE_KEY", # Optional
    "Content-Type" => "application/json"
  ];
  ```

  ```go Go theme={"system"}
  headers := map[string]string{
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", // Optional
    "Content-Type": "application/json"
  }
  ```

  ```ruby Ruby theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", # Optional
    "Content-Type": "application/json"
  }
  ```

  ```java Java theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", // Optional
    "Content-Type": "application/json"
  }
  ```

  ```csharp C# theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", // Optional
    "Content-Type": "application/json"
  }
  ```

  ```rust Rust theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", // Optional
    "Content-Type": "application/json"
  }
  ```
</CodeGroup>

## 壓縮

Ayrshare 所有 API 請求皆支援壓縮。
若要啟用壓縮，請將 `Accept-Encoding` header 設為 `deflate, gzip, br`。

```bash theme={"system"}
  Accept-Encoding: "deflate, gzip, br"
```

當回應較大時（例如呼叫 [/history 端點](/apis/history/overview) 時），建議使用壓縮。

<ul class="custom-bullets">
  <li>只有大於 1024 bytes（1KB）的回應才會被壓縮。</li>

  <li>
    使用的壓縮順序為：先 Brotli（br），接著 gzip，最後 deflate。Brotli 是
    效率最高的壓縮演算法。
  </li>

  <li>
    回應 header 會包含實際使用的內容編碼。例如：若使用 Brotli，
    則 `content-encoding: br`。
  </li>

  <li>
    了解更多關於壓縮以及使用壓縮的好處，請參閱 [Ayrshare
    Blog](https://www.ayrshare.com/blog/http-compression-in-node-js-a-dive-into-gzip-deflate-and-brotli/)。
  </li>
</ul>

<Tip>別忘了依 content encoding 正確解壓縮回應。</Tip>

<CodeGroup>
  ```bash cURL theme={"system"}
  curl -H "Authorization: Bearer API_KEY" \ 
       -H "Profile-Key: PROFILE_KEY" \ # Optional
       -H "Content-Type: application/json" \
       -H "Accept-Encoding: deflate, gzip, br" \ 
       -X GET https://api.ayrshare.com/api
  ```

  ```javascript JavaScript theme={"system"}
  headers: {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", // Optional
    "Content-Type": "application/json",
    "Accept-Encoding": "deflate, gzip, br"
  }
  ```

  ```python Python theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", # Optional
    "Content-Type": "application/json",
    "Accept-Encoding": "deflate, gzip, br"
  }
  ```

  ```php PHP theme={"system"}
  $headers = [
    "Authorization" => "Bearer API_KEY",
    "Profile-Key" => "PROFILE_KEY", # Optional
    "Content-Type" => "application/json",
    "Accept-Encoding" => "deflate, gzip, br"
  ];
  ```

  ```go Go theme={"system"}
  headers := map[string]string{
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", // Optional
    "Content-Type": "application/json",
    "Accept-Encoding": "deflate, gzip, br"
  }
  ```

  ```ruby Ruby theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", # Optional
    "Content-Type": "application/json",
    "Accept-Encoding": "deflate, gzip, br"
  }
  ```

  ```java Java theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", // Optional
    "Content-Type": "application/json",
    "Accept-Encoding": "deflate, gzip, br"
  }
  ```

  ```csharp C# theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", // Optional
    "Content-Type": "application/json",
    "Accept-Encoding": "deflate, gzip, br"
  }
  ```

  ```rust Rust theme={"system"}
  headers = {
    "Authorization": "Bearer API_KEY",
    "Profile-Key": "PROFILE_KEY", // Optional
    "Content-Type": "application/json",
    "Accept-Encoding": "deflate, gzip, br"
  }
  ```
</CodeGroup>

## ID 類型

API 會回傳多種類型的 ID，可用於不同的端點：

### Ayrshare Post ID

此 ID 由 Ayrshare 產生，並由
[/post 端點](/apis/post/post) 在 `id` 欄位中回傳。此 ID 讓你能輕鬆
跨社群網路取得該貼文的分析、對該貼文新增
留言、刪除該貼文等。這是你最常會使用的 ID。

### Social Post ID

每個社群網路都會為貼文與留言指派自己的唯一 ID。
這些 ID 會在 /post 或 /comments 端點的 `postIds` 欄位中回傳。
你可以使用這些 ID（或直接從社群網路取得的 ID）來取得資料，例如透過 [analytics social post ID](/apis/analytics/social-by-id)。

### Ayrshare Comment ID

此 ID 由 Ayrshare 產生，並由
[/comments 端點](/apis/comments/post-comment) 在 `id` 欄位中回傳。此 ID 讓你能輕鬆
跨社群網路取得該留言的分析、回覆該留言、
刪除該留言等。這是你最常會使用的 ID。

當你想取得透過 Ayrshare 發布的特定留言細節時常會用到。

### Social Comment ID

每個社群網路都會為留言指派自己的唯一 ID。
這些 ID 會在 [GET /comments 端點](/apis/comments/get-comments) 的 `commentId` 欄位中回傳。

當你想取得非透過 Ayrshare 發布的特定留言細節時常會用到。

## 錯誤代碼

錯誤會以[標準 HTTP 狀態碼](https://tools.ietf.org/html/rfc2616#section-10)回傳。

更多資訊：

<Card title="HTTP 狀態碼" icon="link" horizontal href="/errors/errors-http">
  進一步了解 HTTP 狀態碼
</Card>

REST API 回應中會包含各類型呼叫特定的詳細錯誤資訊。

更多資訊：

<Card title="Ayrshare 錯誤代碼" icon="link" horizontal href="/errors/errors-ayrshare">
  進一步了解 Ayrshare 特定的錯誤代碼
</Card>

## 時間戳格式

Ayrshare 使用 Zulu Time（又稱 UTC，Coordinated Universal Time）或 ISO 8601 格式的日期字串，以精確、無歧義地表示不同時區的時間。

例如使用 `YYYY-MM-DDThh:mm:ssZ` 格式，並以 `2026-07-08T12:30:00Z` 的形式傳送。
更多範例請參閱 [utctime](https://www.utctime.net/)。

你可以使用你偏好的程式語言將 UTC 格式轉換為本地時間。例如以 JavaScript：

```javascript theme={"system"}
const convertToLocalTime = (isoString) => {
  // Create a new Date object from the ISO string
  const date = new Date(isoString);

  // Extract local time components
  const localDate = date.toLocaleDateString();
  const localTime = date.toLocaleTimeString();

  // Combine the local date and time
  const localDateTime = `${localDate} ${localTime}`;

  return localDateTime;
};
```

## Postman

你可以使用 Postman 來測試你的 REST API 呼叫。

<Card title="Postman" icon="link" horizontal href="/testing/postman">
  了解如何搭配我們的 API 使用 Postman
</Card>

## 隨機貼文、圖片與影片

請參閱[快速入門指南](/quickstart#publish-test-posts)，了解如何在測試時發送隨機貼文、圖片或影片。

## 套件

我們提供 Node.js 與 Python 套件，以及 Bubble.io、Airtable 與 Make 的指南，讓你更輕鬆地進行 RESTful 呼叫。

<CardGroup cols={2}>
  <Card title="Node NPM 套件" icon="cube" iconType="duotone" href="/packages-guides/nodejs" horizontal>
    使用我們的 NodeJS 套件進行整合
  </Card>

  <Card title="Python PyPI 套件" icon="cube" iconType="duotone" href="/packages-guides/python" horizontal>
    使用我們的 Python 套件進行整合
  </Card>

  <Card title="Airtable 指南" icon="book-open" iconType="duotone" href="/packages-guides/airtable" horizontal>
    了解如何搭配 Airtable 使用 Ayrshare
  </Card>

  <Card title="Bubble 外掛與指南" icon="cube" iconType="duotone" href="/packages-guides/bubble" horizontal>
    了解如何搭配 Bubble.io 使用 Ayrshare
  </Card>

  <Card title="Make 指南" icon="book-open" iconType="duotone" href="/packages-guides/make" horizontal>
    了解如何搭配 Make 使用 Ayrshare
  </Card>

  <Card title="Notion 指南" icon="book-open" iconType="duotone" href="/packages-guides/notion" horizontal>
    了解如何搭配 Notion 使用 Ayrshare
  </Card>

  <Card title="FlutterFlow 指南" icon="book-open" iconType="duotone" href="/packages-guides/flutterflow" horizontal>
    了解如何搭配 FlutterFlow 使用 Ayrshare
  </Card>

  <Card title="Retool 指南" icon="book-open" iconType="duotone" href="/packages-guides/retool" horizontal>
    了解如何搭配 Retool 使用 Ayrshare
  </Card>
</CardGroup>
