# X (Twitter) 媒体帖子 API (twitter.user_media)

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

X 媒体帖子按 `username` 读取一个账号主页「媒体」标签页，只收带图片或视频的帖子，从新到旧排列，每条带 `media` 里的图片与视频地址、正文和各项计数。它回答「这个账号发过哪些图和视频、哪类素材传播得好」，适合做视觉内容的竞品分析、给品牌素材库归档，或者挑出高浏览量的视频做二次研究。纯文字帖子不会出现在结果里。账号名也可以直接填主页链接。

翻页把 `next_page_token` 作为 `page_token` 传回，每页条数比文字列表少，也不固定。一页最多 12 条，传 `limit` 也改变不了。第一页里的 `author_media_count` 是作者发过的媒体总数，一条帖子可带多个，拿它估帖子数只能粗估上限。

## Health

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

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| username | not declared | yes | not declared | X 用户短名，可带 @，也可填主页链接 https://x.com/<用户名>；取这个账号主页「媒体」页的帖子（带图片或视频的）。 |
| page_token | not declared | no | not declared | 翻页令牌：把上一次响应里的 next_page_token 原样传回，拿下一页；不传从第一页开始。令牌 24 小时有效，每页算一次调用。 |

## 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 | 作者在原平台的主页链接。 |
| author_follower_count | 作者粉丝数。null 表示不公开。 |
| quote_count | platform-native meaning |
| bookmark_count | 书签（收藏）数。 |
| language | 内容语言代码（如 zh、en），由平台判定，可能不准。 |
| conversation_id | 所属对话串 ID（根推文 ID），同一串的回复据此归在一起。 |
| 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_bio | platform-native meaning |
| author_is_verified | platform-native meaning |
| author_following_count | platform-native meaning |
| author_post_count | 作者推文总数。 |
| author_media_count | 作者发过的媒体数。 |
| author_created_at | platform-native meaning |
| author_banner_url | 作者主页横幅图链接。 |
| 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": "user_media",
  "params": {
    "username": "nasa"
  }
}'
```

```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": "user_media",
        "params": {
            "username": "nasa",
        },
    },
    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": "user_media",
  "results": [
    {
      "next_page_token": …,
      "id": …,
      "url": …,
      "text": …,
      "like_count": …,
      "retweet_count": …,
      "reply_count": …,
      "view_count": …,
      "posted_at": …,
      "author_username": …,
      "author_name": …,
      "author_url": …,
      "author_follower_count": …,
      "quote_count": …,
      "bookmark_count": …,
      "language": …,
      "conversation_id": …,
      "is_quote": …,
      "is_repost": …,
      "is_pinned": …,
      "source": …,
      "media": …,
      "author_id": …,
      "author_bio": …,
      "author_is_verified": …,
      "author_following_count": …,
      "author_post_count": …,
      "author_media_count": …,
      "author_created_at": …,
      "author_banner_url": …,
      "platform": …
    }
  ],
  "next_page_token": …,
  "pagination": { … },
  "count": …,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### `media` 里的地址可以直接拿来存档吗？

可以。`media` 列出这条帖子带的每一张图片、每一段视频的地址，一条帖子可以带多个。先看每项的类型：photo 是图片，video 是视频，animated_gif 是动图。视频项里的 url 是封面图，视频文件本身在码率最高的那个 mp4 地址里，宽高也在同一项里。做素材归档时建议当场取回存到自己的存储，原帖被删除或设为不可见后，这些地址也会跟着失效。归档时也存下 `id` 和 `url`，方便回溯原帖。

### `source` 为什么有时没有，缺了该怎么统计？

`source` 记录发帖用的客户端，比如网页版或手机应用，只有部分帖子会返回，缺失并不代表帖子有问题。平台没给时连这个键都不出现，解析时用「键是否存在」判断，别当成空字符串。分析一个账号的发布习惯时，只统计带 `source` 的那部分帖子，别把缺失当成一种客户端。回复帖子那一页不返回这个键，两边数据合并后，这一栏会有一部分是空的。取值是客户端的名字，例如 Twitter for iPhone，可以直接拿来分组。

### 同一个账号发的视频，怎么挑出表现最好的？

先在 `media` 里确认是视频帖，再按 `view_count` 排序；`like_count`、`retweet_count`、`bookmark_count` 分别反映认同、传播和收藏意愿。比较不同账号时，用 `author_follower_count` 做归一化，大号和小号才放得到一起比。没有浏览量的帖子单独放一边，别混进排序。视频的秒数也在 `media` 里，先按时长分几档，再在每档里比，短片和长片才不会互相压制。

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