Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Python
xdk
Paginate X API v2 responses in Python with iterators or manual pagination tokens.
meta.next_token
import os from xdk import Client client = Client(bearer_token=os.environ["X_BEARER_TOKEN"]) all_posts = [] for page in client.posts.search_recent( query="python", max_results=100, tweet_fields=["created_at", "author_id"], ): if page.data: all_posts.extend(page.data) print(f"Fetched {len(page.data)} posts (total: {len(all_posts)})") if len(all_posts) >= 500: break # Stop early without fetching additional pages
next(...)
pagination_token
first_page = next(client.posts.search_recent( query="python", max_results=100, )) next_token = first_page.meta.next_token if first_page.meta else None if next_token: second_page = next(client.posts.search_recent( query="python", max_results=100, pagination_token=next_token, )) print(f"Second page: {len(second_page.data or [])} posts")