# X (Twitter) 社群搜索 API (twitter.search_communities)

- Canonical page: https://everyinfra.com/twitter-api/search_communities
- Endpoint: POST /api/v1/social with {"platform": "twitter", "action": "search_communities", "params": {...}}
- Price: $0.000806 per call ($0.81 per 1,000 requests); failed and empty results are not charged
- Returns: list, one page of up to 10 per call; the number of rows varies from page to page and a short page is not the end (limit is ignored; pass the top-level next_page_token from the response as page_token for the next page; no next_page_token means the end)
- Pagination: pass next_page_token back as page_token for the next page, other params unchanged; one call per page, tokens last 24 hours
- Mode: sync; add "mode": "async" for slow tasks

社群搜索按 `keyword` 找 X 的社群（Communities），匹配社群名称和话题。每行返回社群的 `id`、名称、主话题 `topic`、成员数 `member_count`、是否标为成人内容 `is_nsfw` 和横幅图 `banner_url`，`url` 是社群在原平台上的可访问链接。它回答「某个话题下有哪些社群、规模多大」，适合找值得监测的社群，或者按成员数给候选社群排序。

一页最多约 10 个社群，传 `limit` 改变不了，判断翻完只看响应里还有没有 `next_page_token`。拿到 `id` 之后，社群资料读单个社群的档案，社群帖子读社群里的帖子。

## Health

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

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| keyword | not declared | yes | not declared | 搜索社群用的关键词，按社群名称和话题匹配。 |
| page_token | not declared | no | not declared | 翻页令牌：把上一次响应里的 next_page_token 原样传回，拿下一页；不传从第一页开始。令牌 24 小时有效，每页算一次调用。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| url | 该记录在原平台上的可访问链接。 |
| name | 名称。用于账号/商品/商家类能力，指该对象本身的名字。 |
| topic | 社群的主话题（如 Finance）。 |
| member_count | platform-native meaning |
| is_nsfw | 社群是否标为成人内容。 |
| banner_url | 社群横幅图链接。 |
| platform | 数据来源平台标识，与请求里的 platform 一致（如 xiaohongshu、tiktok）。 |
| next_page_token | platform-native meaning |

## 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": "twitter",
  "action": "search_communities",
  "params": {
    "keyword": "coffee"
  }
}'
```

```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": "twitter",
        "action": "search_communities",
        "params": {
            "keyword": "coffee",
        },
    },
    timeout=120,
)
print(response.status_code)
print(response.json())
```

## Response example

No real sample for these example parameters yet: structure only, every value is a placeholder (…).

```text
{
  "id": "req_…",
  "platform": "twitter",
  "action": "search_communities",
  "results": [
    {
      "id": …,
      "url": …,
      "name": …,
      "topic": …,
      "member_count": …,
      "is_nsfw": …,
      "banner_url": …,
      "platform": …,
      "next_page_token": …
    }
  ],
  "next_page_token": …,
  "pagination": { … },
  "count": …,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### 社群搜索会返回社群里的帖子吗？

不会。这一页只返回社群本身的名片：名称、话题、成员数这些。要读社群里的帖子，把结果里的 `id` 当作社群 ID，交给社群帖子那一页。`page_token` 24 小时有效，每页算一次调用。

### `is_nsfw` 怎么用？

它标出社群是否被标为成人内容。做名单筛选时，先按 `is_nsfw` 去掉不合适的社群，再按 `member_count` 排序，规模靠前的优先看；`topic` 是社群的主话题，用来确认没有偏题。

### 社群搜索和用户搜索有什么不同？

两页都按 `keyword` 搜，也都按页返回；这一页每页约 10 条，用户搜索约 20 条。返回的东西不同：这一页给社群的话题、成员数和横幅图，没有粉丝数、关注数、发帖数和认证标识，那些是用户搜索里账号才有的。

## Also

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