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

# Reddit API

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

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

## 发布到 Reddit

以下是使用 Reddit API 发布帖子所需的请求体参数。请确保该子版块允许自动化发布。
更多信息请参见 [Reddit 媒体指南](/media-guidelines/reddit) 和 [Reddit 授权](/dashboard/connect-social-accounts/reddit)。

```json Reddit Post theme={"system"}
{
  "post": "Reddit post", // empty string is allowed
  "platforms": ["reddit"], // required
  "redditOptions": {
    "title": "Reddit Post Title", // required
    "subreddit": "test", // required (no "/r/" needed)
    "link": "https://www.website.com" // optional: post a link
  }
}
```

<ul class="custom-bullets">
  <li>`title`（必填）：Reddit 上帖子的标题。</li>

  <li>
    `subreddit`（必填）：发送帖子的目标子版块。请务必遵守该子版块的
    发帖指南。适合用于测试的一个良好子版块是 */r/test/*，可访问：
    [https://www.reddit.com/r/test/](https://www.reddit.com/r/test/)
  </li>

  <li>
    `link`（可选）：如果发布到 Reddit 时你想在子版块中发布一个链接而不是文本。
    虽然 `post` 参数文本仍是必填的，但它不会包含在帖子中，
    因为 Reddit 链接不能有文本正文。
  </li>
</ul>

<Warning>
  发帖前请务必查看该子版块的规则。有些子版块设有 karma 阈值、
  要求成员身份达到一定时间、限制发帖频率、不允许图片，或
  要求添加 flair。此外，大多数子版块对垃圾内容和自我推广有特定的规则。
  不遵守这些规则可能会导致被该子版块或 Reddit 封禁。
</Warning>

## 发布图片到 Reddit

将图片 URL 包含在 `mediaUrl` 参数中，或包含在 `redditOptions` 的 `link` 参数中，即可将图片发布到 Reddit。作为 `link` 发布的图片将解析为完整图片。

`post` 参数文本会被忽略，但为了成功提交帖子仍是必填的。Reddit 限制在其在线 "fancy pants" 编辑器中同时发布图片和文本。这意味着可以发布图片或文本，但不能同时发布两者。

```json Reddit Post with Image theme={"system"}
{
  "post": "Reddit post", // required, but not added to the post
  "platforms": ["reddit"], // required
  "mediaUrls": "https://my-media-url.com",
  "redditOptions": {
    "title": "Reddit Post Title", // required
    "subreddit": "test" // required (no "/r/" needed)
  }
}
```

## 添加 Reddit Flair

一些子版块要求添加 flair。子版块的管理员会预先定义 flair，每个 flair 都有唯一的 ID。在发送到 Ayrshare 的 Reddit 帖子中添加 flair ID 以及可选的 flair 文本（如果文本允许被覆盖）。

```json Reddit Post with Flair theme={"system"}
{
  "redditOptions": {
    "flairId": "jM8nH92enjswas", // Id of the flair
    "flairText": "My New Flair text" // Override the flair text if allowed by flair
  }
}
```

你可以通过调用 [/post/redditFlair](/apis/utils/reddit-get-flair) 端点找到子版块的 flair ID。

## 检查子版块是否存在

使用 [/validate 端点](/apis/validate/check-subreddit) 检查子版块是否存在。

## 为 Reddit 帖子添加富文本格式

如果你想为 Reddit 帖子添加粗体、斜体或上标文本，请使用 [Reddit 风格的 Markdown](https://www.reddit.com/wiki/markdown#wiki_new_reddit-flavored_markdown)。

```json Reddit Post with Rich Text theme={"system"}
{
  "post": "For example, this can be *italic* or **bold** or ^super ",
  "platforms": ["reddit"],
  "redditOptions": {
    "title": "Rich Text Post",
    "subreddit": "test"
  }
}
```

## Reddit 提及

提及其他 Reddit 用户或子版块。

<ul class="custom-bullets">
  <li>通过在帖子文本中添加 `@subreddit` 或 `u/username` 来提及 Reddit 用户。</li>
  <li>通过在帖子文本中添加 `r/subreddit` 来提及子版块。</li>
</ul>

例如：

```json Reddit Post with Mention theme={"system"}
{
  "post": "The best Reddit post ever for user @ayrshare and subreddit r/SiliconValleyHBO",
  "platforms": ["reddit"]
}
```

<Warning>
  请查看提及功能的[重要规则](/testing/post-verification#mentions)。
</Warning>

## 字符限制

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

## 其他端点

<Card title="获取 Reddit Flair" icon="code" href="/apis/utils/reddit-get-flair" horizontal />
