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

# Threads API

> 使用 Threads API 发布内容的选项

<Info>
  Threads 发布通过 Meta 的服务器端爬虫从你的 URL 获取媒体。
  如果你看到 Ayrshare 错误代码 379 — 尤其是在同一次发布中伴随 Instagram 错误 440 或 138 时 —
  请参见 [Meta 媒体爬虫被阻止](/help-center/technical-support/meta_media_crawler_blocked)。
</Info>

## 发布到 Threads

使用 Threads API 发布带有链接和图片的基本帖子的 JSON：

```json Threads Post theme={"system"}
{
  "post": "The best Threads post ever #best #awesome https://www.threads.net", // empty string is allowed
  "mediaUrls": ["https://img.ayrshare.com/012/gb.jpg"],
  "platforms": ["threads"]
}
```

Threads API 有以下要求和限制：

<ul class="custom-bullets">
  <li>
    除非帖子中包含图片或视频，否则 Threads 将自动预览链接。
    在上面的示例中会显示图片。移除图片后，链接
    预览将会显示。
  </li>

  <li>Threads 配置文件在 24 小时滚动周期内限制通过 API 发布 250 篇帖子。</li>
  <li>Threads 每篇帖子只允许 1 个话题标签。</li>
  <li>@mention Threads 用户会收到通知。</li>
  <li>帖子最多 500 个字符。</li>

  <li>
    支持多图/视频帖子，并作为轮播发送。最多可以发送 20 个视频和
    图片。
  </li>

  <li>
    Threads 不支持通过 API 删除。删除必须在 Threads 应用中手动进行。
  </li>

  <li>
    如果你的视频不是以已知的视频扩展名（如 mp4）结尾，请使用 `isVideo`
    参数。详情请参见 [/post 端点](/apis/post/post)。
  </li>

  <li>
    Threads 还支持发送无帖子文本的媒体。如果你不希望包含帖子文本，
    请发送空字符串 `post: ""`。
  </li>

  <li>
    更多信息请参见 [Threads 媒体指南](/media-guidelines/threads) 和 [Threads
    授权](/dashboard/connect-social-accounts/threads)。
  </li>
</ul>

## Threads 选项

你可以使用 `threadsOptions` 参数为帖子设置额外选项。

```json Threads Options theme={"system"}
{
  "threadsOptions": {
    "allowCountries": ["US", "CA"],
    "thread": true,
    "threadNumber": true,
    "mediaUrls": ["https://img.ayrshare.com/012/gb.jpg"] // used when sending as a thread of threads
  }
}
```

Threads 选项是可选字段，可用于控制帖子。

<ParamField body="allowCountries" type="array of strings">
  使用国家/地区代码将帖子限制到特定国家/地区。使用 [国家/地区代码](/iso-codes/country)。

  仅在 Meta 已为你的账户启用地理限制时可用。

  更多信息请参见 [Threads 地理限制](/apis/post/social-networks/threads#geo-restrictions)。
</ParamField>

<ParamField body="thread" type="boolean" default={false}>
  将长帖子拆分为连接的线程系列，可选择编号和媒体。

  更多信息请参见 [线程](/apis/post/social-networks/threads#thread)。
</ParamField>

<ParamField body="threadNumber" type="boolean" default={false}>
  自动在每个线程末尾以 1/n 格式添加编号。

  需要 `thread: true`。
</ParamField>

<ParamField body="mediaUrls" type="array of strings">
  将媒体对象添加到线程系列中。每个媒体对象将按顺序添加到每个线程。

  使用 `null` 跳过特定线程的媒体。使用具有多个 URL 的对象为每个线程添加多个媒体。

  更多信息请参见 [线程媒体](/apis/post/social-networks/threads#thread-media)。
</ParamField>

## 为 Threads 帖子添加换行或富文本

Threads 换行可以通过特殊的 [换行字符](/apis/post/post#line-breaks) 添加到帖子中。

富文本（如粗体或斜体字）可以通过一些 [html 元素](/apis/post/overview#rich-text-posts) 添加到 Threads 帖子。

## 图片和视频轮播

你可以将多张图片或视频作为轮播发布到 Threads；一个轮播最多可以使用 20 张图片或视频（合计）。只需将额外的图片或视频添加到 `mediaUrls` 数组，轮播将自动创建。

```json theme={"system"}
"mediaUrls": ["https://url.com/image.jpg", "https://url.com/video.mp4" ...];  // Max 20 images or videos
```

视频 URL 必须以已知的扩展名（如 mp4）结尾。

## 字符限制

更多信息请参见 [Threads 字符限制](/help-center/technical-support/character_limits#threads-character-limits)。

## 地理限制

你可以使用 `allowCountries` 数组将帖子限制到特定的一个或多个国家/地区。

```json theme={"system"}
{
  "threadsOptions": {
    "allowCountries": ["US", "CA"]
  }
}
```

<ul class="custom-bullets">
  <li>
    `allowCountries`：允许的国家/地区代码数组。参见 [国家/地区代码](/iso-codes/country)。
  </li>
</ul>

<Warning>
  仅在 Meta 已为你的账户启用此功能时，才能对 Threads 使用地理限制（geo-gating）。

  Meta 会根据账户验证、粉丝数量或内容创作者状态等因素决定哪些 Threads 账户有资格使用地理限制。
  如果你的账户符合条件，在创建新的 Threads 帖子时，你将在帖子编辑器中看到地理设置（地球图标）。

  你可以通过检查 [/user](/apis/user/profile-details) 端点中的 `isEligibleForGeoRestrictions` 属性来查看用户配置文件是否符合 Threads 地理限制的条件。
</Warning>

## Threads 提及

通过在帖子文本中添加 @handle 来提及其他 Threads 用户。例如：

```json theme={"system"}
{
  "post": "The best social media API @Ayrshare ever!",
  "mediaUrls": ["https://images.com"],
  "platforms": ["threads"]
}
```

<Warning>
  被 @提及的用户将收到提及通知。请查看提及功能的
  [重要规则](/testing/post-verification#mentions)。
</Warning>

如果达到配额，将返回错误消息。

## 线程

Threads 的 thread，也称为 threadstorm，是 Threads 上一系列相连的帖子，可以让你分享超出单个帖子字符限制的更长想法，一起查看时呈现为一个连续的叙述。

### 发布线程

Threads 线程可以通过 API 发布。线程是一个被拆分为一组回复帖子的帖子，这些回复在 Threads 中相互关联。你可以自动拆分帖子，也可以在帖子文本中指定[线程分隔符](/apis/post/social-networks/threads#thread-breaks)。

```json Threads Thread theme={"system"}
{
  "threadsOptions": {
    "thread": true,        // required for threadstorm
    "threadNumber": true,  // optional to add numbers to each thread
    "mediaUrls": ["https://site.com/image1.png", "https://site.com/image2.png", ...]  // optional one media object is added to a thread in order
  }
}
```

<ul class="custom-bullets">
  <li>
    `thread: true` 根据换行自动将帖子文本拆分为多个线程。
  </li>

  <li>
    `threadNumber: true` 自动以 1/n 格式在线程末尾添加编号。
    例如，5 个线程中的第 2 个将追加：2/5
  </li>

  <li>
    `mediaUrls: [array of urls]` 按顺序将每个媒体对象（图片或视频）添加到线程。
    每个线程仅按顺序添加一个媒体对象。
  </li>
</ul>

#### 线程媒体

##### 跳过媒体

通过在数组中使用 `null` 跳过某个线程的媒体。例如：

`["https://site.com/image1.png", null, "https://site.com/image2.png"]`

这会将 image1 放在第一个帖子上，第二个帖子没有图片，image2 放在第三个帖子上。

##### 多个媒体

通过在 `mediaUrls` 数组中添加带有媒体 URL 的对象 `{}`，可以为线程中的单个帖子添加多个媒体对象。可以使用任何唯一的对象键。例如：

```json Threads Thread with Multiple Media URLs theme={"system"}
{
  "threadsOptions": {
    "thread": true,
    "threadNumber": true,
    "mediaUrls": [
      "https://img.ayrshare.com/random/photo-1.jpg",
      {
        "1": "https://img.ayrshare.com/random/photo-2.jpg",
        "2": "https://img.ayrshare.com/random/photo-3.jpg"
      },
      "https://img.ayrshare.com/random/photo-4.jpg"
    ]
  }
}
```

在此示例中，第一个帖子将包含 photo-1.jpg，第二个帖子包含 photo-2.jpg 和 photo-3.jpg，第三个帖子包含 photo-4.jpg。

#### 线程分隔符

Ayrshare 会自动将帖子文本拆分为适合 Threads 长度（> 500 个字符）的帖子。在创建线程时，我们优先考虑在可能的情况下将完整句子保留在一个帖子中。如果一个句子放不下，我们会在句子之间拆分。对于非常长的句子，我们会在单词之间拆分。在单词过长的极少情况下，我们会拆分单词本身。

你也可以手动向帖子文本添加 `\n\n` 段落分隔符，以指示应创建一个独立的线程。如果帖子文本中有 `\n\n`，我们将不会自动将帖子拆分为线程。

例如：

```json Example Threads Thread theme={"system"}
{
  "post": "This is post 1\n\nThis is post 2.",
  "platforms": ["threads"],
  "threadsOptions": {
    "thread": true
  }
}
```

将生成线程中的两个帖子。

如果你想添加段落但不拆分为多个帖子，请使用 `\u2063\n\u2063\n`。

```json Threads Thread with Paragraphs theme={"system"}
{
  "post": "This is paragraph 1\u2063\n\u2063\nThis is paragraph 2.",
  "platforms": ["threads"],
  "threadsOptions": {
    "thread": true
  }
}
```

由于帖子少于 500 个字符，将生成一个包含两个段落的帖子。

### 删除线程

Threads 不支持通过 API 删除。删除必须在 Threads 应用中手动进行。
