---
title: "Groups"
description: "搜索 Reddit 社区、自动补全社区名称，或列出某用户活跃的社区。"
---

```http
GET | POST /v1/reddit/groups
```

参数可以用 `GET` 的查询字符串发送，也可以用 `POST` 的 JSON 请求体发送，两者等价。

## 传入内容

| 传入 | 读取内容 | 说明 |
|---|---|---|
| `query` | 社区搜索 |  |
| `prefix` | 名称自动补全：名称以其开头的社区 | `includeNsfw`；仅一页 |
| `username` | 某用户活跃的社区 |  |

每次调用只传一个来源。所有标识符也都接受页面 URL。

## 参数

| Parameter | Type | Required | Notes |
|---|---|---|---|
| `cursor` | string |  | Opaque cursor from the previous page's `cursor`. Pass it alone for the next page. |
| `includeNsfw` | boolean |  | prefix only: include over-18 communities. |
| `limit` | integer 1–100 |  | Items per page, 1–100. |
| `prefix` | string |  | Autocomplete: communities whose name starts with this (fast, one page). |
| `query` | string |  | Search communities by keyword. |
| `username` | string |  | The communities a user is active in: username or profile URL. |

## 请求

```bash tab="cURL"
curl "https://gateway.apinoa.com/v1/reddit/groups?query=photography&limit=3" \
  -H "x-api-key: $APINOA_API_KEY"
```

```js tab="JavaScript"
const params = new URLSearchParams({ query: "photography", limit: "3" });
const res = await fetch(`https://gateway.apinoa.com/v1/reddit/groups?${params}`, {
  headers: { "x-api-key": process.env.APINOA_API_KEY },
});
const { success, data, error } = await res.json();
```

```python tab="Python"
import os

import requests

res = requests.get(
    "https://gateway.apinoa.com/v1/reddit/groups",
    params={"query": "photography", "limit": "3"},
    headers={"x-api-key": os.environ["APINOA_API_KEY"]},
)
body = res.json()
```

## 响应

在 `data` 中返回 [`Group`](/docs/api-reference/sns/response-schema#group) [`Page`](/docs/api-reference/sns/response-schema#page)。 真实响应的节选：数组只保留前几项，长文本已截断。

```json
{
  "success": true,
  "data": {
    "platform": "reddit",
    "items": [
      {
        "platform": "reddit",
        "kind": "community",
        "id": "2qh2a",
        "name": "photography",
        "url": "https://www.reddit.com/r/photography/",
        "description": "/r/photography is a place to politely discuss the tools, technique, art and culture of photography and to post topics t…",
        "avatarUrl": "https://styles.redditmedia.com/t5_2qh2a/styles/communityIcon_ewee979e9tib1.png?width=256&s=98f37a3e36d9c6c3631fe569571f…",
        "bannerUrl": "https://styles.redditmedia.com/t5_2qh2a/styles/bannerBackgroundImage_quu3wdl77tib1.png?width=4000&s=c4b33e56a54192ba98c…",
        "createdAt": "2008-01-25T05:32:49.000Z",
        "counts": {
          "members": 5668327
        },
        "sensitive": false,
        "ext": {
          "fullname": "t5_2qh2a",
          "title": "Photography",
          "sidebar": "/r/photography is a place to politely discuss the tools, technique, art and culture of photography and to post topics t…",
          "type": "public",
          "language": "en",
          "submissionType": "any",
          "advertiserCategory": "Lifestyles",
          "submitText": "**PLEASE REMEMBER TO FLAIR YOUR POSTS**\n\n* This sub is for discussing photography, not just sharing your work. We have…",
          "settings": {
            "allowImages": false,
            "allowVideos": false,
            "allowVideoGifs": false,
            "allowPolls": false,
            "allowGalleries": false,
            "spoilersEnabled": true,
            "allowDiscovery": true,
            "restrictPosting": true,
            "restrictCommenting": false,
            "allOriginalContent": false,
            "linkFlairEnabled": true,
            "userFlairEnabled": false,
            "crosspostable": false,
            "archivePosts": false,
            "commentScoreHideMins": 180,
            "suggestedCommentSort": "confidence",
            "wikiEnabled": true,
            "allowedMediaInComments": [
              "giphy",
              "static"
            ]
          }
        }
      }
    ],
    "cursor": "RjvzT7CZ0WloEEGA_XTHSRLU2Ia7PEAPgIHxnz5MuTkxEAed4QiaxwGSMV4GjEyZuFRoNHN7XBfL0ccvbyKMrSdBmcbPTkJZWrF51xxHeqeRbGWY1xuM6tm…"
  }
}
```

## 错误

| 状态 | 代码 | 含义 |
|---|---|---|
| 400 | `INVALID_CURSOR` | 该 `cursor` 不是本操作返回的。请不带它重新开始。 |
| 400 | `INVALID_PARAMS` | 参数缺失、未知或超出范围。消息中会指出是哪一个。 |
| 401 | `UNAUTHORIZED` | 缺少 `x-api-key` 请求头，或密钥已吊销或未知。 |
| 402 | `INSUFFICIENT_BALANCE` | 余额不足以支付本次调用。请在控制台充值。 |
| 404 | `NOT_FOUND` | 账号、帖子或分组不存在，或为私密、已删除、有年龄限制。 |
| 429 | `MARKETPLACE_SATURATED` | 并发调用过多。请等待 `Retry-After` 秒后重试。 |
| 502 | `UPSTREAM_ERROR` | 平台返回了无法使用的内容。请退避后重试。 |

全部错误代码见 [Errors](/docs/errors)。失败的调用不计费。

## 价格

**Price** $0.001 per call. [List price](https://apinoa.com/en/pricing); the rate steps down above 1,000 calls a day.
