How to Collect Donald Trump public social data via API

Author:TwexAPI Team
EN
Read in:
English
日本語中文
TwexAPI
public social data
User Timeline
Public Account Research
Python
Trump

Use TwexAPI to collect public Donald Trump public platform account data with profile metadata, timeline pagination, and optional advanced search filters.

Quick Answer

Donald Trump public social platform data collection can use TwexAPI Advanced Search with from:realDonaldTrump and date filters to export public posts, media fields, and interaction data. Save the query, retrieval time, raw JSON, cursors, and source URLs so research and media-monitoring datasets remain auditable.

FAQ

Why use TwexAPI instead of the first-party developer API for this workflow?

For political figure archives, 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-08-20, first-party developer 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.

For a public account dataset, the most reliable structure is not a one-off keyword search. Start with the account profile, collect timeline pages with cursors, and use search only when you need a filtered subset.

This guide uses realDonaldTrump as the example screen name. Verify the current handle before running any collection job, especially when you are building a repeatable archive.

Collection Plan

Answer: Collection Plan 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-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

Use three TwexAPI endpoints:

TaskEndpointWhen to use it
Get public account metadataGET /twitter/{screen_name}/aboutSave the account snapshot before collecting posts.
Page through account postsPOST /twitter/{screen_name}/timeline/pageCollect timeline posts with cursor-based pagination.
Search public X resultsPOST /twitter/advanced_search/pageFilter the account's posts by topic, phrase, or search operator.

Save raw responses as well as normalized rows. That makes the dataset easier to audit when a field mapping or export rule changes later.

Get Account Metadata

Answer: Get Account Metadata 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-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

curl --request GET \
  --url https://api.twexapi.io/twitter/realDonaldTrump/about \
  --header 'Authorization: Bearer <token>'

Keep this account snapshot separate from your post table. It can include account identifiers, display fields, bio fields, and public counters returned by the API.

Page Through Timeline Posts

Answer: Page Through Timeline Posts 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-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

POST /twitter/{screen_name}/timeline/page accepts count and next_cursor. Omit next_cursor on the first request. If the response returns has_next_page: true, send the returned next_cursor with the next request.

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

A page response includes data plus pagination fields.

{
  "code": 200,
  "msg": "success",
  "data": [],
  "has_next_page": true,
  "next_cursor": "DAAHCgAB...",
  "requested_count": 20,
  "effective_count": 20,
  "parsed_count": 20
}

Python Collector

Answer: Python Collector 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-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

This collector fetches a bounded number of timeline pages and normalizes each post into a reviewable row.

1import os
2from typing import Any
3
4import requests
5
6TOKEN = os.environ["TWEXAPI_BEARER_TOKEN"]
7SCREEN_NAME = "realDonaldTrump"
8BASE_URL = "https://api.twexapi.io"
9
10def headers() -> dict[str, str]:
11    return {"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"}
12
13def get_profile(screen_name: str) -> dict[str, Any] | None:
14    response = requests.get(
15        f"{BASE_URL}/twitter/{screen_name}/about",
16        headers=headers(),
17        timeout=30,
18    )
19    response.raise_for_status()
20    return response.json().get("data")
21
22def get_timeline_page(
23    screen_name: str,
24    *,
25    count: int = 20,
26    next_cursor: str | None = None,
27) -> dict[str, Any]:
28    payload: dict[str, Any] = {"count": count}
29    if next_cursor:
30        payload["next_cursor"] = next_cursor
31
32    response = requests.post(
33        f"{BASE_URL}/twitter/{screen_name}/timeline/page",
34        headers=headers(),
35        json=payload,
36        timeout=30,
37    )
38    response.raise_for_status()
39    return response.json()
40
41def normalize_post(post: dict[str, Any]) -> dict[str, Any]:
42    tweet_id = post.get("tweet_id") or post.get("id")
43    return {
44        "tweet_id": tweet_id,
45        "created_at": post.get("created_at_datetime") or post.get("created_at"),
46        "text": post.get("full_text") or post.get("text") or "",
47        "favorite_count": post.get("favorite_count") or 0,
48        "retweet_count": post.get("retweet_count") or 0,
49        "reply_count": post.get("reply_count") or 0,
50        "quote_count": post.get("quote_count") or 0,
51        "url": f"https://x.com/i/status/{tweet_id}",
52    }
53
54def collect_timeline(screen_name: str, max_pages: int = 3) -> list[dict[str, Any]]:
55    rows: list[dict[str, Any]] = []
56    cursor = None
57
58    for _ in range(max_pages):
59        page = get_timeline_page(screen_name, count=20, next_cursor=cursor)
60        rows.extend(normalize_post(post) for post in page.get("data", []))
61
62        if not page.get("has_next_page"):
63            break
64        cursor = page.get("next_cursor")
65        if not cursor:
66            break
67
68    return rows
69
70if __name__ == "__main__":
71    profile = get_profile(SCREEN_NAME)
72    posts = collect_timeline(SCREEN_NAME, max_pages=2)
73    print(profile.get("screen_name") if profile else SCREEN_NAME, len(posts))

Optional Topic Search

Answer: Optional Topic Search 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-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

Use timeline pagination for the account archive. Use advanced search when you need a narrower dataset.

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 economy"],
    "sortBy": "Latest"
  }'

Store the exact query with each result row. This matters when someone later asks why a post was included or excluded.

Data Hygiene

Answer: Data Hygiene 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-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

  • Record screen_name, run time, endpoint, query, and cursor for every job.
  • Use tweet_id as the deduplication key.
  • Save raw JSON before flattening fields.
  • Do not treat interaction counts as proof of accuracy, importance, or public opinion.
  • Review quoted posts, media, and reply context before using posts in a report.

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-08-20, first-party developer API Post and User reads list at $5 and $10 per 1,000 resources; rate limits vary by endpoint.

For a public account such as realDonaldTrump, the practical workflow is profile metadata, timeline pagination, optional topic search, and careful export hygiene.

That gives you a repeatable collection process without adding unsupported pricing claims, invented response data, or analysis the API did not perform.

How to Collect Donald Trump public social data via API