> ## Documentation Index
> Fetch the complete documentation index at: https://docs.brightdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 发送你的第一个 Reddit API 请求

> 使用可复制粘贴的代码示例向每个 Bright Data Reddit 爬虫 API 端点发送同步请求。

本指南介绍如何向每个 Bright Data Reddit 爬虫 API 端点发送同步请求。完成后，你将拥有收集帖子、发现帖子和收集评论的可用示例。

## 前提条件

* 一个带有有效 API 密钥的 [Bright Data 账户](https://www.bright.cn/cp/start)
* 已完成 [快速开始](/cn/products/scrapers/reddit/quickstart)

## 请求结构

每个同步请求都遵循相同模式：

```
POST https://api.brightdata.com/datasets/v3/scrape?dataset_id={DATASET_ID}&format=json
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

[{"url": "https://www.reddit.com/..."}]
```

端点之间唯一变化的是 `dataset_id` 和输入形式。

<Note>
  同步请求最多支持 20 个 URL，超时限制为 1 分钟。如果请求时间更长，API 会自动返回 `snapshot_id`。参见 [异步请求](/cn/products/scrapers/scrapers-library/async-requests)。
</Note>

## 帖子 — 按 URL 收集

通过 URL 爬取特定 Reddit 帖子。

**数据集 ID：** `gd_lvz8ah06191smkebj4`

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_lvz8ah06191smkebj4&format=json" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '[{"url": "https://www.reddit.com/r/learnpython/comments/1asdf12/how_do_i_start_learning_python/"}]'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.brightdata.com/datasets/v3/scrape",
      params={"dataset_id": "gd_lvz8ah06191smkebj4", "format": "json"},
      headers={
          "Authorization": "Bearer YOUR_API_KEY",
          "Content-Type": "application/json",
      },
      json=[{"url": "https://www.reddit.com/r/learnpython/comments/1asdf12/how_do_i_start_learning_python/"}],
  )

  print(response.json())
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_lvz8ah06191smkebj4&format=json",
    {
      method: "POST",
      headers: {
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify([
        { url: "https://www.reddit.com/r/learnpython/comments/1asdf12/how_do_i_start_learning_python/" }
      ]),
    }
  );

  const data = await response.json();
  console.log(data);
  ```
</CodeGroup>

你应该看到 `200` 响应。这需要 10 到 30 秒。

[完整帖子 — 按 URL 收集模式](/cn/api-reference/scrapers/social-media-apis/reddit#collect-by-url)

## 帖子 — 按子版块 URL 发现

爬取来自特定子版块的最近帖子，可选按 `new`、`top` 或 `hot` 排序。

**数据集 ID：** `gd_lvz8ah06191smkebj4`

<Note>
  发现端点最好通过 [`/trigger`](/cn/products/scrapers/scrapers-library/async-requests) 异步使用，因为它们可能返回许多结果。下面的同步示例仅用于快速测试。
</Note>

```bash theme={null}
curl -X POST \
  "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_lvz8ah06191smkebj4&format=json&type=discover_new&discover_by=subreddit_url" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{"url": "https://www.reddit.com/r/learnpython/", "sort_by": "hot"}]'
```

[完整按子版块 URL 发现模式](/cn/api-reference/scrapers/social-media-apis/reddit#discover-by-subreddit-url)

## 帖子 — 按关键词发现

查找匹配搜索词的 Reddit 帖子，按日期过滤。

**数据集 ID：** `gd_lvz8ah06191smkebj4`

```bash theme={null}
curl -X POST \
  "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_lvz8ah06191smkebj4&format=json&type=discover_new&discover_by=keyword" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{"keyword": "machine learning", "date": "Past week", "num_of_posts": 20}]'
```

[完整按关键词发现模式](/cn/api-reference/scrapers/social-media-apis/reddit#discover-by-keywords)

## 评论 — 按 URL 收集

爬取来自 Reddit 帖子或特定评论线程的所有评论，可选按年龄过滤。

**数据集 ID：** `gd_lvzdpsdlw09j6t702`

```bash theme={null}
curl -X POST \
  "https://api.brightdata.com/datasets/v3/scrape?dataset_id=gd_lvzdpsdlw09j6t702&format=json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{"url": "https://www.reddit.com/r/learnpython/comments/1asdf12/", "days_back": 7}]'
```

[完整评论 — 按 URL 收集模式](/cn/api-reference/scrapers/social-media-apis/reddit#comments-api)

## 相关内容

<CardGroup cols={2}>
  <Card title="异步批量请求" icon="layer-group" href="/cn/products/scrapers/scrapers-library/async-requests">
    在单个异步请求中爬取数千个帖子或运行关键词发现任务。
  </Card>

  <Card title="API 参考" icon="code" href="/cn/api-reference/scrapers/social-media-apis/reddit">
    完整端点规范、参数和响应模式。
  </Card>
</CardGroup>
