> ## 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，让你能够轻松发送社交媒体帖子并获取分析。适用于各种规模的开发者和企业。

社交媒体 REST API 通过单一统一的接口为开发者提供对多个社交网络的编程访问。
通过 Ayrshare 的社交 API，你可以管理社交媒体活动，包括创建和删除帖子、检索分析、参与评论和评价、管理直接消息、创建 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 计划，请参见 [Business 计划概述](/multiple-users/business-plan-overview)、[Launch 计划概述](/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>使用相关关键词自动生成话题标签的选项。</li>
  <li>帖子历史跟踪，包括非 Ayrshare 帖子。</li>
  <li>评价管理：检索、回复和删除评价响应。</li>
  <li>RSS feed 集成，用于自动化内容发布。</li>
  <li>媒体库：上传和存储照片和视频以用于帖子。</li>
  <li>[社交帖子验证系统](/testing/post-verification) 以保护你的社交账户安全。</li>
</ul>

## Business 计划和 Launch 计划

[Business 计划](/multiple-users/business-plan-overview) 和 [Launch 计划](/multiple-users/business-launch-overview) 用于管理多个用户和客户的功能：

<ul class="custom-bullets">
  <li>使用户能够将自己的社交媒体账户关联到你的平台。</li>
  <li>使用 OAuth 实现安全的单点登录，实现快速账户关联。</li>
  <li>通过 API 以编程方式创建和删除用户配置文件。</li>
  <li>访问高级用户分析。</li>
  <li>Webhook 支持实时更新。</li>
  <li>在支持的平台上管理直接消息。</li>
  <li>从现有帖子创建 Facebook 广告。</li>
</ul>

联系我们了解更多关于 [Business 计划](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>
  探索统一消息 API
</Card>

## Max Pack

使用 [Max Pack 附加包](/additional/maxpack) 获取更多功能：

<Card title="Max Pack" icon="link" href="/additional/maxpack" horizontal>
  通过我们的 Max Pack 附加包解锁高级功能，如 AI 驱动的内容生成、增强的分析和扩展的
  平台支持。
</Card>

## 观看如何使用社交 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>

## 社交 API 演示

如果你使用 Node.js，请查看社交 API 演示代码，开始构建你自己的社交 API 集成。

<Card title="社交 API 演示" icon="github" href="https://github.com/ayrshare/social-api-demo" horizontal>
  探索我们的 Node.js 演示代码，快速启动你的社交 API 集成
</Card>

## Base URL

Ayrshare API 所有端点的基础 URL 相同。

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

## 授权

Ayrshare 通过在 HTTP header 中传递的 Authorization 令牌来验证 API 请求。请务必与 API Key 一起发送 `Bearer`。API Key 可以在 Ayrshare 仪表板中切换到你的 Primary Profile 找到。

如果你是 Business 或 Enterprise 用户，你可以创建带有 Profile Key 的用户配置文件来管理多个客户。Profile Key 在你的请求 header 中使用。
API Key 也必须在用户配置文件的请求 header 中使用。

<Tip>
  Premium 计划应该在请求的 header 中仅使用 API Key。Business 和 Enterprise
  计划在代表用户配置文件进行交互时，应在请求的 header 中使用 Profile Key
  。
</Tip>

### API Key 格式

`Authorization: Bearer API_KEY`，将 API\_KEY 替换为你的 Primary Profile API Key，可以 [在 Ayrshare 仪表板中找到](/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>
  在 Ayrshare 仪表板左侧导航面板中的 API Key 页面下获取你的密钥 API Key。

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

  你的 header 应该包含：

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

### Profile Key 格式

Profile Key 用于代表用户配置文件进行交互。
仅适用于 Business 或 Enterprise 计划。

`Profile-Key: PROFILE_KEY`，将 PROFILE\_KEY 替换为用户的 [Profile Key](/multiple-users/manage-user-profiles#get-the-profile-key)。

**在 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 仪表板左侧导航面板中的 Profile Key 页面下 [找到 Profile Key](/multiple-users/manage-user-profiles#get-the-profile-key)。
  在用户配置文件页面切换到你想要使用的配置文件。
  此外，Profile Key 也会在 [创建用户配置文件](/apis/profiles/create-profile) 端点的响应中返回。

  然后你可以在请求的 header 中使用 Profile Key：

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

  你的 header 应同时包含 API Key 和 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） |

这些 header 在 2026 年 3 月 31 日之后是必需的。没有有效 BYO 凭据的 X/Twitter 端点请求将被拒绝。

<Info>
  **一对密钥，用于每个请求。** 你为每个 Ayrshare 账户创建一个 X Developer 应用，并在每个面向 X 的请求中使用相同的 `X-Twitter-OAuth1-Api-Key` 和 `X-Twitter-OAuth1-Api-Secret` 值，无论请求针对哪个子配置文件（`Profile-Key`）。你不需要为每个客户或每个最终用户生成或轮换密钥。
</Info>

有关分步说明、代码示例和故障排除，请参见 [X BYO Key 设置指南](/dashboard/connect-social-accounts/x-twitter-byo-keys)。

通过 [MCP Server](/additional/mcp-action-server) 驱动 X/Twitter 时同样应用相同的两个 header — 参见 [连接与设置](/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 字节 (1KB) 的响应才会被压缩。</li>

  <li>
    使用的压缩顺序：Brotli (br) 优先，然后是 gzip，最后是 deflate。Brotli 是最
    高效的压缩算法。
  </li>

  <li>
    响应 header 包含所用的内容编码。例如：`content-encoding: br` 如果
    使用了 Brotli。
  </li>

  <li>
    在 [Ayrshare
    博客](https://www.ayrshare.com/blog/http-compression-in-node-js-a-dive-into-gzip-deflate-and-brotli/) 中了解更多关于压缩以及使用压缩的好处。
  </li>
</ul>

<Tip>不要忘记使用内容编码正确解压响应。</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 类型

返回的 ID 有多种类型，可用于各个端点：

### Ayrshare Post ID

此 ID 由 Ayrshare 生成，并从
[/post 端点](/apis/post/post) 的 `id` 字段返回。此 ID 使
在社交网络上获取帖子的分析、为帖子添加评论、
删除帖子等操作变得容易。这是你最常使用的 ID。

### 社交帖子 ID

每个社交网络为其帖子和评论分配自己的唯一 ID。
这些 ID 在 /post 或 /comments 端点的 `postIds` 字段中返回。
你可以使用这些 ID 或直接从社交网络获取的 ID 来检索数据，例如使用 [analytics 社交帖子 ID](/apis/analytics/social-by-id)。

### Ayrshare 评论 ID

此 ID 由 Ayrshare 生成，并从
[/comments 端点](/apis/comments/post-comment) 的 `id` 字段返回。此 ID 使
在社交网络上获取评论的分析、为评论添加回复、
删除评论等操作变得容易。这是你最常使用的 ID。

如果你想获取通过 Ayrshare 发布的特定评论的详细信息，这通常很有用。

### 社交评论 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 时间（也称为 UTC 协调世界时）或 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">
  了解如何将 Postman 与我们的 API 一起使用
</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>
    了解如何将 Ayrshare 与 Airtable 一起使用
  </Card>

  <Card title="Bubble 插件和指南" icon="cube" iconType="duotone" href="/packages-guides/bubble" horizontal>
    了解如何将 Ayrshare 与 Bubble.io 一起使用
  </Card>

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

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

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

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