# Reddit 社区帖子 API (reddit.subreddit_posts)

- Canonical page: https://everyinfra.com/reddit-api/subreddit_posts
- Endpoint: POST https://api.everyinfra.com/api/v1/social with {"platform": "reddit", "action": "subreddit_posts", "params": {...}}
- Price: $0.000556 per call ($0.56 per 1,000 requests); failed calls and empty results are not charged
- Returns: list, default 10, max 100 per call
- Mode: sync; add "mode": "async" for slow tasks

Reddit 社区帖子按 `subreddit` 列出一个版块里的帖子，每条带标题、正文、作者、点赞数、评论数、发布时间、分类标签 `flair`，链接帖还带站外地址 `external_link` 和域名 `domain`，图片帖带图片地址。它回答「这个社区里大家在讨论什么」，适合产品团队收集用户反馈、市场团队观察品类讨论，以及研究者抽样一个社区的话题。单次上限 100 条，是用户内容那一页的两倍。

用 `sort` 选最新、热门、高分、上升或相关性；`date_range` 只在 `sort` 为 `top` 时生效。版块名可以写 python、r/python 或完整社区链接。`community` 是不含 r/ 前缀的版块名。

## Health

- Live health (24h percent, hourly and daily trends): https://api.everyinfra.com/api/v1/social/availability?platform=reddit&action=subreddit_posts

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| subreddit | not declared | yes | not declared | subreddit_posts 的社区名，例如 python 或 r/python，或完整社区 URL。 |
| date_range | enum: all_time / past_day / past_hour / past_month / past_week / past_year | no | not declared | 社区帖子的相对时间窗；all_time 不限，past_hour/day/week/month/year 为对应的最近时间。Reddit 在 sort=top 时才会应用该窗口。 |
| sort | enum: newest / popular / relevance / rising / top | no | not declared | 社区帖子排序：newest 最新、popular 热门、top 高分、rising 上升、relevance 相关性。 |
| limit | integer (1–100) | no | 10 | 这次调用最多返回的条数，整数，1–100；不传按默认值，实际返回可能少于这个数。超过上限会在扣费前返回 422。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| url | 该记录在原平台上的可访问链接。 |
| title | 标题。平台无标题概念时（如纯文本帖）为 null。 |
| text | 正文内容，已去除 HTML 标签，全文返回、不截断（个别平台的列表结果本身只有摘要，以该平台的字段说明为准）。 |
| author_username | 作者用户名（@handle），通常可用于拼 URL。 |
| community | 所属 subreddit 名称（不含 r/ 前缀）。 |
| like_count | 点赞数。null 表示该平台或该接口不公开此数据，不等于 0。 |
| comment_count | 评论数。null 表示不公开，不等于 0。 |
| posted_at | 发布时间，ISO 8601 格式、UTC 时区（如 2026-08-07T12:34:56+00:00）。平台只给非标准字符串时原样透传，解析前建议做容错。null 表示平台未公开。 |
| flair | 帖子的分类标签（flair）原文。 |
| domain | 帖子链接的域名（文字帖为 self.版块名 或 reddit.com）。 |
| external_link | 链接帖指向的站外地址。 |
| thumbnail_url | 缩略图链接，分辨率低于 image_url。 |
| image_urls | 帖子里的图片地址。 |
| platform | 数据来源平台标识，与请求里的 platform 一致（如 xiaohongshu、tiktok）。 |

## Example

```bash
curl -X POST 'https://api.everyinfra.com/api/v1/social' \
  -H "Authorization: Bearer $EVERYINFRA_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "platform": "reddit",
  "action": "subreddit_posts",
  "params": {
    "subreddit": "python"
  }
}'
```

```python
import os
import requests

response = requests.post(
    "https://api.everyinfra.com/api/v1/social",
    headers={"Authorization": f"Bearer {os.environ['EVERYINFRA_API_KEY']}"},
    json={
        "platform": "reddit",
        "action": "subreddit_posts",
        "params": {
            "subreddit": "python",
        },
    },
    timeout=120,
)
print(response.status_code)
print(response.json())
```

## Response example

Real response to the example request above, captured 2026-09-26T08:56:04Z. `results` and `count` are real with personal information (names, handles, avatars, profile links, contact details) removed; the list keeps the first 2 of 10. `id`, `billing` and `quota` differ on every call, so only their shape is shown.

```text
{
  "id": "req_…",
  "platform": "reddit",
  "action": "subreddit_posts",
  "results": [
    {
      "id": "1wq79hw",
      "url": "https://www.reddit.com/r/Python/comments/1wq79hw/image_upload_file_type_verification_on_fastapi/",
      "title": "Image upload file type verification on FastAPI",
      "author_username": "•••",
      "community": "Python",
      "like_count": 17,
      "comment_count": 14,
      "posted_at": "2026-09-25T20:38:54.239000+00:00",
      "platform": "reddit"
    },
    {
      "id": "1wqbw40",
      "url": "https://www.reddit.com/r/Python/comments/1wqbw40/saturday_daily_thread_resource_request_and/",
      "title": "Saturday Daily Thread: Resource Request and Sharing! Daily Thread",
      "author_username": "•••",
      "community": "Python",
      "like_count": 5,
      "comment_count": 0,
      "posted_at": "2026-09-26T00:00:08.837000+00:00",
      "platform": "reddit"
    }
  ],
  "count": 10,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### 为什么设置了 `date_range` 却没效果？

Reddit 只在 `sort` 为 `top` 时应用时间窗。想看本周最高分的帖子，`sort` 传 `top`、`date_range` 传 `past_week`；按最新或热门排序时，时间窗不起作用。从 `past_hour` 到 `past_year` 五档窗口配上 `top`，能分别看最近一小时直到最近一年里得分最高的帖子，`all_time` 则不限时间。只想看最近发的帖子，用 `newest` 排序，想抓正在升温的用 `rising`，时间窗留给 `top`。

### `flair` 有什么用？

`flair` 是帖子的分类标签原文。它是原文，没有做归一，不同版块的标签体系不一样，跨版块汇总前要先自己对齐。按 `flair` 分组统计，能快速看出这个社区里各类帖子各占多少，也方便只挑出某一类帖子细读。想只留站内讨论，挑 `domain` 为 self.版块名 或 reddit.com 的行；`external_link` 有值的是指向站外的链接帖。图片帖的图片地址在 `image_urls`，`thumbnail_url` 是分辨率更低的缩略图。

### 社区帖子和用户内容怎么选？

研究一个话题或产品的讨论，用社区帖子，从版块出发；研究某个用户的发言习惯和常去的版块，用用户内容，从人出发。两页的返回字段相同，区别在入口和单次上限，默认都是 10 条。社区里谁发帖最多，按作者统计一下就知道。社区帖子里的 `author_username` 可以直接交给用户内容继续查。要比较几个版块，就每个版块各调一次，再按 `community` 合并。

## Also

- Capability catalog (no key): https://api.everyinfra.com/api/v1/social/catalog?platform=reddit
- OpenAPI: https://everyinfra.com/openapi.json · Agents guide: https://everyinfra.com/agents.md
