> ## 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 發布貼文時必填的 body 參數。請務必確認該 subreddit 允許自動發布內容。
更多資訊請參閱 [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`（必填）：要發布貼文的 subreddit。請務必遵守該 subreddit 的
    發布規範。適合用來測試的 subreddit 是 */r/test/*，可於下列網址檢視：
    [https://www.reddit.com/r/test/](https://www.reddit.com/r/test/)
  </li>

  <li>
    `link`（選填）：如果你想在 Reddit 上發布連結而非純文字，可使用此參數。
    雖然 `post` 參數的文字仍為必填，但不會包含在貼文中，因為 Reddit 的
    連結貼文不允許同時包含文字內容。
  </li>
</ul>

<Warning>
  發布前請務必先確認 subreddit 的規則。有些 subreddit 有 karma 門檻、
  要求加入一段時間才能發文、限制發文頻率、不允許圖片，或必須加上 flair。
  此外，大多數 subreddit 都對垃圾訊息與自我宣傳有明確規範。
  未遵守這些規則可能會被該 subreddit 或 Reddit 封鎖。
</Warning>

## 發布圖片到 Reddit

發布圖片到 Reddit 的方式有兩種：一是將圖片 URL 放入 `mediaUrl` 參數，二是放入 `redditOptions` 的 `link` 參數。以 `link` 方式發布的圖片會直接顯示為完整圖片。

`post` 參數的文字會被忽略，但仍必須填寫才能成功送出貼文。Reddit 只允許透過線上的「fancy pants」編輯器同時發布圖片與文字，因此透過 API 只能擇一發布，不能同時發布圖片與文字。

```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

有些 subreddit 要求加上 flair。Subreddit 的管理員會預先定義 flair，每個 flair 都有一個唯一的 ID。在傳送至 Ayrshare 的 Reddit 貼文中，加入 flair ID，如果該 flair 允許覆寫文字，也可以選擇性地加入 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) 端點來取得 subreddit 的 flair ID。

## 檢查 subreddit 是否存在

可以使用 [/validate 端點](/apis/validate/check-subreddit) 檢查 subreddit 是否存在。

## 在 Reddit 貼文中加入 rich text 格式

若要在 Reddit 貼文中加入粗體、斜體或上標文字，請使用 [Reddit-flavored 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 使用者或 subreddit。

<ul class="custom-bullets">
  <li>在貼文文字中加入 `@subreddit` 或 `u/username` 來提及 Reddit 使用者。</li>
  <li>在貼文文字中加入 `r/subreddit` 來提及某個 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 />
