# Mastodon 时间线 API (mastodon.timeline)

- Canonical page: [https://everyinfra.com/mastodon-api/timeline](https://everyinfra.com/mastodon-api/timeline?utm_medium=ai_doc&utm_campaign=page_md)
- Endpoint: POST https://api.everyinfra.com/api/v1/social with {"platform": "mastodon", "action": "timeline", "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

时间线没有必填参数，直接读取一个 Mastodon 实例的时间线。返回的帖子和话题内容那一页字段相同，作者、点赞转嘟评论三项互动、语言和话题标签都有。它回答「这个实例上正在发什么」，适合了解一个实例的社区气氛，或者在决定监测哪些话题和账号之前先看一眼。

不传 `instance` 时，这一页读的是 fosstodon.org，而其他 Mastodon 入口默认读 mastodon.social，所以同样不传参数，两边读到的不是同一个实例。要换实例，传域名，不带协议或路径。

## Health

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

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| 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": "timeline",
  "params": {}
}'
```

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

## Response example

Real response to the example request above, captured 2026-09-26T08:56:04Z. `results` and `count` are real with personal information (names, handles, avatars, profile links, contact details) removed; the list keeps the first 2 of 20. `id`, `billing` and `quota` differ on every call, so only their shape is shown.

```text
{
  "id": "req_…",
  "platform": "mastodon",
  "action": "timeline",
  "results": [
    {
      "id": "•••",
      "url": "https://mastodon.social/@•••/117336731269576457",
      "text": "You rested for a moment, regaining 0 hitpoints.\n---\nIn the distance you see a 👺 Bone Devil\n❤️ 75-210  ❗9 ✨ 5000\n\n#c172",
      "author_name": "•••",
      "author_username": "•••",
      "instance": "mastodon.social",
      "like_count": 0,
      "reblog_count": 0,
      "comment_count": 0,
      "language": "en",
      "posted_at": "2026-09-26T09:53:51+00:00",
      "platform": "mastodon",
      "hashtags": [
        "c172"
      ]
    },
    {
      "id": "•••",
      "url": "https://piaille.fr/@•••/117336731142115049",
      "text": "Deuxième sac chat du jour, un tigré aux yeux d'or\n\nBandoulière réglable et personnalisable (pas obligé que ce soit le léopard)\n\nVotre sac avec tête de chat personnalisable ? Même prix, bipez-moi.\n\nhttps://lhaulde.com/produit/f-778-2/",
      "author_name": "•••",
      "author_username": "•••",
      "instance": "piaille.fr",
      "like_count": 0,
      "reblog_count": 0,
      "comment_count": 0,
      "language": "fr",
      "posted_at": "2026-09-26T09:53:49+00:00",
      "platform": "mastodon",
      "media_urls": [
        "https://cdn.fosstodon.org/cache/media_attachments/files/117/336/731/213/888/112/original/1849630821cfea37.png"
      ]
    }
  ],
  "count": 20,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### 不传 `instance` 会读哪个实例？

读 fosstodon.org，这是时间线这一页的默认值。显式传 `instance` 时只填域名，不要带 https:// 或路径；需要明确读哪个实例，就别依赖默认值。

### 时间线怎么和话题内容、用户内容配合？

先在时间线里看 `hashtags` 和 `author_username`，找出常出现的标签和活跃的账号，再把标签交给话题内容、把账号交给用户内容，深入读下去。时间线本身没有按标签或按账号筛选的参数。

### 一次能读多少条？

默认读 20 条，单次最多 100 条。没有翻页参数，所以一次调用拿到的是实例时间线上的一小段，不是完整历史。`is_reblog` 能标出其中的转嘟，统计原创内容前先把它们去掉。

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