# Mastodon 用户内容 API (mastodon.user_posts)

- Canonical page: [https://everyinfra.com/mastodon-api/user_posts](https://everyinfra.com/mastodon-api/user_posts?utm_medium=ai_doc&utm_campaign=page_md)
- Endpoint: POST https://api.everyinfra.com/api/v1/social with {"platform": "mastodon", "action": "user_posts", "params": {...}}
- Price: $0.001389 per call ($1.39 per 1,000 requests); failed calls and empty results are not charged
- Returns: list, default 20, max 100 per call
- Mode: sync; add "mode": "async" for slow tasks

用户内容按 `username` 读取一个 Mastodon 账号发的帖子，每条带正文、作者、`like_count`、`reblog_count`、`comment_count`、`language`、`media_urls`、`hashtags`，以及标明是否转嘟的 `is_reblog`。它回答「这个账号发了什么、哪些反响好」，适合跟踪一个创作者或机构账号，做内容复盘。

不同实例上的同名账号不是同一个人，查之前先确认对方在哪个实例上。一次默认 20 条，最多 100 条，这一页没有翻页参数。

## Health

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

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| username | not declared | yes | not declared | Mastodon 账号名或 user@instance 形式的完整账号，开头 @ 可省略。仅传短用户名且未指定 instance 时默认 mastodon.social；不同实例的同名账号不是同一人。 |
| instance | not declared | no | not declared | Mastodon 实例域名，不带协议或路径。timeline 默认 fosstodon.org，其他入口默认 mastodon.social；显式 instance 优先于 username 中的实例，因此二者应保持一致。 |
| limit | integer (1–100) | no | 20 | 这次调用最多返回的条数，整数，1–100；不传按默认值，实际返回可能少于这个数。超过上限会在扣费前返回 422。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| url | 该记录在原平台上的可访问链接。 |
| text | 正文内容，已去除 HTML 标签，全文返回、不截断（个别平台的列表结果本身只有摘要，以该平台的字段说明为准）。 |
| author_name | 作者昵称（显示名）。 |
| author_username | 作者用户名（@handle），通常可用于拼 URL。 |
| author_url | 作者在原平台的主页链接。 |
| instance | 所属实例域名。 |
| like_count | 点赞数。null 表示该平台或该接口不公开此数据，不等于 0。 |
| reblog_count | 转嘟数。 |
| comment_count | 评论数。null 表示不公开，不等于 0。 |
| language | 内容语言代码（如 zh、en），由平台判定，可能不准。 |
| is_reblog | 是否为转嘟（Mastodon 的转发）。 |
| posted_at | 发布时间，ISO 8601 格式、UTC 时区（如 2026-08-07T12:34:56+00:00）。平台只给非标准字符串时原样透传，解析前建议做容错。null 表示平台未公开。 |
| platform | 数据来源平台标识，与请求里的 platform 一致（如 xiaohongshu、tiktok）。 |
| media_urls | platform-native meaning |
| hashtags | 正文里的话题标签数组，按出现顺序；没有时不出现这个字段。 |

## 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": "mastodon",
  "action": "user_posts",
  "params": {
    "username": "<USERNAME>@mastodon.social"
  }
}'
```

```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": "mastodon",
        "action": "user_posts",
        "params": {
            "username": "<USERNAME>@mastodon.social",
        },
    },
    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": "mastodon",
  "action": "user_posts",
  "results": [
    {
      "id": …,
      "url": …,
      "text": …,
      "author_name": …,
      "author_username": …,
      "author_url": …,
      "instance": …,
      "like_count": …,
      "reblog_count": …,
      "comment_count": …,
      "language": …,
      "is_reblog": …,
      "posted_at": …,
      "platform": …,
      "media_urls": …,
      "hashtags": …
    }
  ],
  "count": …,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### `username` 到底要怎么写？

写完整账号最稳妥，也就是 user@instance，开头的 @ 可以省略。只写短用户名且没有 `instance` 时，默认去 mastodon.social 找；账号在别的实例上，就必须写完整账号或者传 `instance`。示例里的写法是 <USERNAME>@mastodon.social，使用时把用户名和实例域名都换成你要查的账号。

### `username` 里的实例和 `instance` 不一致会怎样？

以显式传的 `instance` 为准，它的优先级高于 `username` 里的实例。所以两处应保持一致，不一致的话读到的可能是另一个实例上的同名账号。

### 读到的帖子里有转嘟吗，怎么分？

看 `is_reblog`，为真表示这一条是转嘟。想只统计账号自己写的内容，把这类行去掉再算 `like_count` 和 `reblog_count`。想按话题而不是按账号找内容，改用话题内容，传标签词。

## Also

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