# 怎麼拿到一個推特帳號發過的所有推文？

> 採集一個 X（推特）帳號的全部帖子：先從新到舊翻時間線，更早的部分用 from: 加日期分段搜尋。費用、程式碼和限制。

網頁版：https://okdata.online/zh-hant/answers/get-all-tweets-from-account/

**簡短回答：**用 X 帳號帖子列表從新到舊翻頁（每頁約 20 條，$0.002），更早的時間段用 X 帖子搜尋加 from:使用者名稱 和 since:/until: 日期補齊（每頁 $0.002）。一個每天發 10 條的帳號，一年約 183 頁，大約 $0.366。

比如你想把競品今年在 X 上發的東西全部拉下來，看看他們宣佈了什麼、哪些帖子反響好。兩個介面就夠了。[X 帳號帖子列表](/zh/apis/x/users/posts/list/)按從新到舊一頁頁返回這個帳號的帖子，翻過起始日期就停。更早的時間段，或者想確認沒有漏掉，用 [X 帖子搜尋](/zh/apis/x/posts/search/)加 `from:使用者名稱` 和時間範圍，一段一段往前補。

## 先估個量

先用 [X 帳號資訊](/zh/apis/x/users/get/)（$0.0004）看一眼。返回的 `posts` 欄位是 X 自己統計的發帖總數，裡面包含回覆和轉發，所以你最後採到的條數一般對不上，但能看出要處理的是 400 條還是 4 萬條。

| 帳號情況 | 帖子數 | 頁數 | 費用 |
|---|---|---|---|
| 每天 2 條，一年 | 約 730 | 37 | $0.074 |
| 每天 10 條，一年 | 約 3,650 | 183 | $0.366 |
| 同上，改用按月分段搜尋 | 約 3,650 | 183 | $0.366 |

## 程式碼：翻時間線直到截止日期

```python
import os, requests

API = "https://api.okdata.online/v1"
H = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}
START = "2026-01-01"

def get(path, **params):
    body = requests.get(f"{API}/{path}", headers=H, params=params, timeout=60).json()
    if body["code"] != "ok":
        raise RuntimeError(f"{body['code']}: {body['message']}")
    return body

posts, cursor = [], None
while True:
    body = get("x/users/posts/list", username="openai", **({"cursor": cursor} if cursor else {}))
    batch = body["data"]["items"]
    posts += [p for p in batch if p["published_at"] >= START]
    if not body["page"]["has_more"] or (batch and batch[-1]["published_at"] < START):
        break
    cursor = body["page"]["next_cursor"]

print(len(posts), "條，起始日期", START)
```

走搜尋這條路時，按月迴圈，`query=f"from:openai since:{a} until:{b}"`，配合 `sort=latest`。只想要帳號自己發的帖子、不要它回覆別人的，再加上 `-filter:replies`。

## 限制

- 時間線能往回翻多深由 X 決定。翻不到起始日期就停了的話，改用按月分段搜尋。
- 受保護帳號和已刪除的帖子採不到。
- 每頁算一次呼叫，失敗的那頁只要請求到了平台，也照常計費。

## 官方渠道

X 官方 API 的使用者時間線最多隻返回最近 3,200 條。官方全量歷史搜尋配合 `from:` 可以回溯到 2006 年，按量付費帳號可用，每條 0.005 美元。只採一個幾千條帖子的帳號，這個價格不算貴；如果你需要 X 官方對完整性的保證，就選它。要是每週都要跟十幾個競品帳號，按頁計費會便宜不少。每週跑一次的完整做法見[競品監測方案](/zh/solutions/competitor-monitoring/)。

## 用到的介面

- [X 帳號帖子列表](https://okdata.online/zh/apis/x/users/posts/list/) `x.users.posts.list`：$0.002/次 · 每頁約 20 條帖子
- [X 帖子搜尋](https://okdata.online/zh/apis/x/posts/search/) `x.posts.search`：$0.002/次 · 每頁約 20 條帖子
- [X 帳號資訊](https://okdata.online/zh/apis/x/users/get/) `x.users.get`：$0.0004/條 · 每次最多 $0.04

## 更多X（推特）內容

- [X（推特） API](https://okdata.online/zh/apis/x/)
- [怎麼按關鍵詞搜 X（推特）帖子並匯出](https://okdata.online/zh/guides/x-search-posts-by-keyword/)
- [怎麼每天記錄多個國家的 X（推特）趨勢](https://okdata.online/zh/guides/x-trends-by-country/)
- [怎麼拿到一個推特帳號發過的所有推文？](https://okdata.online/zh/answers/get-all-tweets-from-account/)
- [snscrape 抓推特一直報 blocked (404)，有能用的替代嗎？](https://okdata.online/zh/answers/snscrape-twitter-blocked-404/)
- [推特免費的學術 API 沒了，研究者現在怎麼採集推文？](https://okdata.online/zh/answers/twitter-academic-api-alternative/)
- [twscrape 報 No active accounts、帳號一直被鎖，還有別的辦法嗎？](https://okdata.online/zh/answers/twscrape-no-active-accounts/)
- [有沒有按次付費、能拿 TikTok 和 X（推特）公開資料的 API？](https://okdata.online/zh/answers/tiktok-x-pay-per-call-api/)
- [有沒有給 Claude 用的 X（推特）MCP 服務，能搜帖子、讀回覆、看粉絲？](https://okdata.online/zh/answers/x-twitter-mcp-server-claude/)
- [平台官方 API 和第三方資料介面怎麼選（2026）](https://okdata.online/zh/compare/official-apis-vs-data-apis/)
- [怎麼選社交媒體資料 API（2026）](https://okdata.online/zh/compare/social-media-data-apis/)
- [帳號資訊介面](https://okdata.online/zh/roles/accounts-get/)
- [帳號作品列表介面](https://okdata.online/zh/roles/accounts-posts-list/)
- [內容搜尋介面](https://okdata.online/zh/roles/posts-search/)

## 資料來源

這個問題出現過的地方（讀取於 2026-11-12）：

- https://stackoverflow.com/questions/6083982
- https://stackoverflow.com/questions/29018875

更新於 2026-11-12
