# X (Twitter) 社群帖子 API (twitter.community_posts)

- Canonical page: https://everyinfra.com/twitter-api/community_posts
- Endpoint: POST /api/v1/social with {"platform": "twitter", "action": "community_posts", "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 20 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

社群帖子按 `community_id` 读取 X 社群（Communities）里的最新帖子，每条带正文、浏览与互动数、`media`、作者用户名和认证标识，`is_quote` 标出引用推文。它回答「这个社群最近在聊什么」，适合监测一个社群的讨论，给运营找选题，或者观察某个圈子的内容风向。

`community_id` 填社群的数字 ID，也可以直接填社群链接 https://x.com/i/communities/<id>。`is_repost` 和 `is_pinned` 分别标出转发和置顶，统计社群里的原创讨论时可以先把它们分开。

## Health

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

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| community_id | not declared | yes | not declared | 社群的数字 ID，也可填社群链接 https://x.com/i/communities/<id>；返回社群里的最新帖子。 |
| page_token | not declared | no | not declared | 翻页令牌：把上一次响应里的 next_page_token 原样传回，拿下一页；不传从第一页开始。令牌 24 小时有效，每页算一次调用。 |
| url | not declared | no | not declared | 兼容写法，可以不传：社群链接直接填进必填的 community_id 即可；两个都填时以 community_id 为准。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| next_page_token | platform-native meaning |
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| url | 该记录在原平台上的可访问链接。 |
| text | 正文内容，已去除 HTML 标签，全文返回、不截断（个别平台的列表结果本身只有摘要，以该平台的字段说明为准）。 |
| like_count | 点赞数。null 表示该平台或该接口不公开此数据，不等于 0。 |
| retweet_count | 转发数。 |
| reply_count | 回复数，通常用于评论的子回复。null 表示不公开。 |
| view_count | 浏览/播放数。null 表示不公开，不等于 0。 |
| posted_at | 发布时间，ISO 8601 格式、UTC 时区（如 2026-08-07T12:34:56+00:00）。平台只给非标准字符串时原样透传，解析前建议做容错。null 表示平台未公开。 |
| author_username | 作者用户名（@handle），通常可用于拼 URL。 |
| author_name | 作者昵称（显示名）。 |
| author_url | 作者在原平台的主页链接。 |
| quote_count | platform-native meaning |
| language | 内容语言代码（如 zh、en），由平台判定，可能不准。 |
| is_quote | 是否引用推文。 |
| is_repost | platform-native meaning |
| is_pinned | platform-native meaning |
| source | 发推客户端（如 Twitter for iPhone）；平台没给时没有这个键。 |
| media | 推文图片 / 视频：type（photo / video / animated_gif）、url（图片或视频封面）、width、height、duration_sec（视频秒数）、video_url（码率最高的 mp4）。 |
| author_id | 作者在原平台的唯一 ID。 |
| author_is_verified | platform-native meaning |
| 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": "twitter",
  "action": "community_posts",
  "params": {
    "community_id": "1508567430188126209"
  }
}'
```

```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": "community_posts",
        "params": {
            "community_id": "1508567430188126209",
        },
    },
    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": "community_posts",
  "results": [
    {
      "next_page_token": …,
      "id": …,
      "url": …,
      "text": …,
      "like_count": …,
      "retweet_count": …,
      "reply_count": …,
      "view_count": …,
      "posted_at": …,
      "author_username": …,
      "author_name": …,
      "author_url": …,
      "quote_count": …,
      "language": …,
      "is_quote": …,
      "is_repost": …,
      "is_pinned": …,
      "source": …,
      "media": …,
      "author_id": …,
      "author_is_verified": …,
      "platform": …
    }
  ],
  "next_page_token": …,
  "pagination": { … },
  "count": …,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### 社群 ID 从哪里来？

已经有社群链接时，直接填链接，或者取 x.com/i/communities/ 后面的数字。只知道话题时，先用社群搜索按关键词找，结果里每一行的 `id` 就是这里要填的社群 ID。`url` 只是兼容写法，链接直接填进 `community_id` 即可。

### 怎么持续监测一个社群的新帖？

定期从第一页读起：返回的是社群里的最新帖子，每页约 20 条，按 `id` 去重后和上一次比对，多出来的就是新帖。每页算一次调用，`page_token` 24 小时内有效，大社群先定好每次读几页。

### 社群帖子的字段和账号媒体帖子有什么不同？

这一页没有书签数、对话编号，也没有作者的粉丝数和简介，带作者的用户名、名称、主页链接和认证标识。要分析某个发帖人的体量，先拿到 `author_username`，再去读他的用户内容或粉丝列表。

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