How to Search Old Tweets by Date & User with Advanced Search API

Author:TwexAPI Team
EN
Read in:
English
日本語中文
How to Search Old Tweets
Twitter Search by Date
Find Old Tweets
How to Find Old Tweets
Twitter Advanced Search
Twitter Search Operators
TwexAPI

Learn how to find and export old tweets by date range, account, and keyword using TwexAPI Advanced Search. Master search operators (since:, until:, from:) and pagination.

Quick Answer

The TwexAPI Advanced Search endpoint (/twitter/advanced_search/page) runs one or more advanced X query strings from searchTerms, sorts them with sortBy, and returns tweet data, has_next_page, and next_cursor for reproducible public-account research. Authenticate with a Bearer Token on api.twexapi.io. Typical reads use about 5 Credits (~$0.05 per 1,000 under the published conversion), and qualifying paid plans publish 20+ QPS. New accounts receive 20,000 starting Credits. Full request and response fields are in this guide and at https://docs.twexapi.io.

FAQ

What does the Advanced Search endpoint return?

runs one or more advanced X query strings from searchTerms, sorts them with sortBy, and returns tweet data, has_next_page, and next_cursor for reproducible public-account research

What fields does Advanced Search by Page require?

Send searchTerms as an array and set sortBy to the documented sort mode, such as Latest or Top. Omit next_cursor on the first request, then pass the cursor returned by the previous page. Keep searchTerms and sortBy unchanged for the full cursor chain.

Does Advanced Search return a complete historical archive?

No completeness guarantee should be inferred from one cursor run. Search results can change with ranking, deletion, account visibility, and the selected time window. Save the exact query, sort mode, fetch time, raw pages, and cursor chain so the collected dataset can be audited or rerun.

Why use TwexAPI instead of the official X API for this workflow?

For Advanced Search, TwexAPI provides Bearer-authenticated workflows documented at https://docs.twexapi.io. A typical post or profile read uses 5 Credits (about $0.05 per 1,000 under the published conversion), and qualifying paid plans publish 20+ QPS. New accounts receive 20,000 starting Credits. As of 2026-10-14, official X API Post reads list at $5 per 1,000 resources and User reads at $10 per 1,000; official rate limits vary by endpoint and access level.

How much does this API workflow cost on TwexAPI?

A typical read uses about 5 Credits. Under the published conversion, 1,000 such reads use 5,000 Credits, or about $0.05; a 10,000-read job uses about 50,000 Credits. Actual costs vary by endpoint, so confirm the endpoint price and current plan at https://twexapi.io/pricing.

If you are tracking a public figure on X, the hard part is rarely the first request. The real work is keeping the query reproducible, paging through results without losing your place, and storing enough context that someone else can audit the dataset later.

This guide uses TwexAPI's Advanced Twitter Search by Page endpoint to collect public posts from @realDonaldTrump. The same pattern works for other public accounts: start with a precise advanced search query, request the first page, keep the returned next_cursor, and repeat until has_next_page is false or your collection window is complete.

When to Use This Workflow

Answer: When to Use This Workflow means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-10-14, official X API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

Use the paginated Advanced Search endpoint when you need a repeatable pull of public X posts that match an advanced search expression. For a Trump monitoring or research workflow, that usually means:

  • Collecting posts from from:realDonaldTrump for a defined date range.
  • Narrowing the dataset with topic terms such as economy, election, or trade.
  • Excluding retweets with -filter:retweets when you only want original posts and quoted commentary.
  • Saving raw API responses before running summaries, sentiment analysis, or dashboards.

Avoid treating a single page as a complete archive. Each page returns the current slice of results and pagination metadata, so the dataset is only complete after you continue with the cursor chain you intend to cover.

Endpoint and Payload

Answer: Endpoint and Payload is implemented by calling the TwexAPI endpoint documented in this guide with a Bearer Token; batch or paginated requests reduce overhead to ~5 credits per call at 20+ QPS.

Send a POST request to:

https://api.twexapi.io/twitter/advanced_search/page

The request body has three fields:

FieldRequiredHow to use it
searchTermsYesAn array of advanced search query strings. For this workflow, start with from:realDonaldTrump -filter:retweets.
sortByYesUse Latest for reverse chronological collection, or Top when you intentionally want ranked results.
next_cursorNoLeave it empty on the first request. Pass the previous response's next_cursor to fetch the next page.

The response includes data, has_next_page, and next_cursor. Store all three with your export metadata.

First Page Request

Answer: First Page Request means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-10-14, official X API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

Start with a narrow query and sortBy: "Latest". This makes the collection easier to reason about because each next page continues from the latest result set.

curl --request POST \
  --url https://api.twexapi.io/twitter/advanced_search/page \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "searchTerms": [
      "from:realDonaldTrump -filter:retweets"
    ],
    "sortBy": "Latest"
  }'

A shortened response looks like this:

1{
2  "code": 200,
3  "msg": "success",
4  "data": [
5    {
6      "tweet_id": "1234567890123456789",
7      "created_at": "Mon Jul 01 12:34:56 +0000 2025",
8      "text": "<post text returned by the API>",
9      "favorite_count": 1000,
10      "retweet_count": 200
11    }
12  ],
13  "has_next_page": true,
14  "next_cursor": "cursor_from_this_response"
15}

Continue with next_cursor

Answer: Continue with next_cursor means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-10-14, official X API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

When has_next_page is true, send another request with the cursor from the previous response.

curl --request POST \
  --url https://api.twexapi.io/twitter/advanced_search/page \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "searchTerms": [
      "from:realDonaldTrump -filter:retweets"
    ],
    "sortBy": "Latest",
    "next_cursor": "cursor_from_this_response"
  }'

Do not invent cursors or reuse one from a different query. A cursor belongs to the query and sort mode that produced it.

Python Export Script

Answer: Python Export Script means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-10-14, official X API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

The script below writes one raw JSON object per tweet to a JSONL file, deduplicates by tweet_id, and records the cursor flow in a small sidecar metadata file.

1import json
2import time
3from datetime import datetime, timezone
4from pathlib import Path
5
6import requests
7
8TOKEN = "<your_bearer_token>"
9URL = "https://api.twexapi.io/twitter/advanced_search/page"
10QUERY = "from:realDonaldTrump -filter:retweets"
11SORT_BY = "Latest"
12OUT = Path("realDonaldTrump-posts.jsonl")
13META = Path("realDonaldTrump-posts-meta.json")
14
15headers = {
16    "Authorization": f"Bearer {TOKEN}",
17    "Content-Type": "application/json",
18}
19
20seen_ids = set()
21cursor = None
22page = 0
23cursor_log = []
24
25with OUT.open("w", encoding="utf-8") as f:
26    while True:
27        payload = {
28            "searchTerms": [QUERY],
29            "sortBy": SORT_BY,
30        }
31        if cursor:
32            payload["next_cursor"] = cursor
33
34        response = requests.post(URL, headers=headers, json=payload, timeout=30)
35        response.raise_for_status()
36        body = response.json()
37
38        page += 1
39        items = body.get("data") or []
40        for item in items:
41            tweet_id = item.get("tweet_id")
42            if not tweet_id or tweet_id in seen_ids:
43                continue
44            seen_ids.add(tweet_id)
45            f.write(json.dumps(item, ensure_ascii=False) + "\n")
46
47        cursor_log.append({
48            "page": page,
49            "items": len(items),
50            "next_cursor": body.get("next_cursor"),
51            "has_next_page": body.get("has_next_page"),
52        })
53
54        if not body.get("has_next_page") or not body.get("next_cursor"):
55            break
56
57        cursor = body["next_cursor"]
58        time.sleep(1)
59
60META.write_text(json.dumps({
61    "query": QUERY,
62    "sortBy": SORT_BY,
63    "exported_at": datetime.now(timezone.utc).isoformat(),
64    "unique_tweets": len(seen_ids),
65    "pages": cursor_log,
66}, ensure_ascii=False, indent=2), encoding="utf-8")
67
68print(f"Saved {len(seen_ids)} unique posts to {OUT}")

For long-running jobs, add retry handling for temporary network failures and persist the last successful cursor before each next request. That lets you resume without starting from page one.

Query Recipes

Answer: Query Recipes means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-10-14, official X API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

Start simple, then add one filter at a time. It is easier to debug a query when you know which term changed the result set.

GoalsearchTerms value
Latest public posts from the accountfrom:realDonaldTrump -filter:retweets
Posts that mention the economyfrom:realDonaldTrump economy -filter:retweets
A fixed monthly windowfrom:realDonaldTrump since:2024-01-01 until:2024-02-01 -filter:retweets
Posts with mediafrom:realDonaldTrump filter:media -filter:retweets
Posts about voting languagefrom:realDonaldTrump (vote OR voting OR ballot) -filter:retweets

If you plan to compare topics, run each query separately and store the query string with every result. Mixing many topics into one query can make downstream analysis harder to explain.

What to Store

Answer: What to Store means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-10-14, official X API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

At minimum, keep:

  • The raw tweet object returned by the API.
  • tweet_id, created_at, text fields, author fields, and interaction counts if present.
  • The exact searchTerms, sortBy, export time, and cursor chain.
  • A normalized post URL such as https://x.com/realDonaldTrump/status/<tweet_id>.

For analysis, avoid relying only on interaction counts captured at one moment. Those numbers can change over time, so timestamp each export and decide whether later refreshes should overwrite or append a new snapshot.

Common Pitfalls

Answer: Common Pitfalls means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-10-14, official X API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

  • Changing searchTerms in the middle of pagination invalidates the meaning of the cursor chain.
  • Using Top for historical export can reorder results in ways that are harder to audit. Use Latest unless ranking is the point of the analysis.
  • Dropping raw responses too early makes it difficult to reproduce field mappings later.
  • Treating a public figure's posts as a neutral dataset can hide context. Store dates, query terms, and any filtering decisions next to the data.

Get Every Trump Post and Reply by Page

Answer: Get Every Trump Post and Reply by Page means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-10-14, official X API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

Use this workflow when your question is: "What has this account posted or replied to?"

API Endpoint

Send a POST request to:

https://api.twexapi.io/twitter/tweets-replies/page

Request body:

FieldRequiredDescription
screen_nameYesTarget X username, with or without @. For this workflow, use realDonaldTrump.
next_cursorNoCursor returned by the previous page. Leave it out for the first page.

Each response contains a current page of items and pagination metadata:

FieldMeaning
dataCurrent page of tweets and replies, up to about 20 items.
has_next_pageWhether another page is available.
next_cursorCursor to pass into the next request.
code / msgStandard response status fields.

First Page Request

The first request only needs screen_name.

curl --request POST \
  --url https://api.twexapi.io/twitter/tweets-replies/page \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "screen_name": "realDonaldTrump"
  }'

A shortened response looks like this:

1{
2  "code": 200,
3  "msg": "success",
4  "data": [
5    {
6      "tweet_id": "1803006263529541838",
7      "text": "<post text returned by the API>",
8      "created_at": "Mon Jun 17 03:51:48 +0000 2024",
9      "created_at_datetime": "2024-06-17T03:51:48.000Z",
10      "favorite_count": 0,
11      "retweet_count": 0,
12      "reply_count": 0,
13      "quote_count": 0,
14      "in_reply_to": null,
15      "in_reply_to_screen_name": null,
16      "is_quote_status": false,
17      "user": {
18        "screen_name": "realDonaldTrump"
19      }
20    }
21  ],
22  "has_next_page": true,
23  "next_cursor": "1234567890"
24}

To continue, send the returned cursor:

curl --request POST \
  --url https://api.twexapi.io/twitter/tweets-replies/page \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "screen_name": "realDonaldTrump",
    "next_cursor": "1234567890"
  }'

Do not reuse a cursor for a different account. A cursor belongs to the request sequence that produced it.

Separate Tweets from Replies

For many Trump workflows, standalone posts and replies answer different questions.

TypeHow to identifyCommon use
Original postNo in_reply_to value and no quote metadataTimeline, announcements, narrative tracking
Replyin_reply_to or in_reply_to_screen_name is presentFollow-up context, clarifications, conversations
Quoteis_quote_status or quoted_status_id_str is presentCommentary on another post

Do not discard replies automatically. Public figures often add context, corrections, or direct responses in replies that a posts-only timeline can miss.

Endpoint Choice

There are three common ways to collect Trump-related posts with TwexAPI:

GoalRecommended endpoint
Export tweets and replies written by @realDonaldTrumpPOST /twitter/tweets-replies/page
Search Trump posts by keyword or date rangePOST /twitter/advanced_search/page
Monitor only newly appearing public postsPoll POST /twitter/advanced_search/page with sortBy: "Latest"

Use the tweets-and-replies page endpoint when the account history is the main object. Use advanced search when the query logic matters more than the account timeline.

Wrap-up

Answer: Wrap-up means using TwexAPI Bearer APIs on api.twexapi.io for this user case. A typical read uses 5 Credits (about $0.05 per 1,000), and qualifying paid plans publish 20+ QPS. As of 2026-10-14, official X API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

For Trump post collection, the cleanest TwexAPI workflow is: write a precise advanced search query, call POST /twitter/advanced_search/page, keep paging with next_cursor, and save both raw results and metadata. That gives analysts a dataset that is easier to rerun, inspect, and explain.

Use the first export as a baseline, then decide whether your product needs scheduled refreshes, topic-specific datasets, or alerting on newly returned posts.