Install
Authenticate
Basic Example
Search tweets and write durable JSON Lines handoff rows:Workflow: Search Tweets to JSON Lines, CSV, or XLSX
This job is for backend workers that need searchable tweet data in a stable handoff format for queues, data lakes, analyst CSV files, or XLSX workbooks. It callsGET /x/tweets/search through client.X.Tweets.Search, requests the newest matching tweets, and writes each returned tweet as one JSON object per line.
XTweetSearchParams request so the Go fields stay aligned with GET /x/tweets/search. The generated params map directly to the REST endpoint:
Q
Go field
Q maps to REST q. Use it for the required X search query with keywords, handles, hashtags, or operators.Limit
Go field
Limit maps to REST limit. Use it as a 1 to 200 upper bound for a bounded pull. If page.HasNextPage is true, keep the same Q, filters, QueryType, and Limit when you continue with page.NextCursor.Cursor
Go field
Cursor maps to REST cursor. Pass the opaque cursor from NextCursor to request the next page.SinceTime
Go field
SinceTime maps to REST sinceTime. Use it as the ISO 8601 lower time bound.UntilTime
Go field
UntilTime maps to REST untilTime. Use it as the ISO 8601 upper time bound.QueryType
Go field
QueryType maps to REST queryType. Use Latest for chronological results or Top for engagement-ranked results.Returned Data & Handoff
client.X.Tweets.Search returns PaginatedTweets:
Tweets
JSON field
tweets. Contains tweet records with ID, Text, Author, CreatedAt, LikeCount, ReplyCount, RetweetCount, QuoteCount, BookmarkCount, ViewCount, and IsNoteTweet when available.HasNextPage
Go field
HasNextPage. JSON field has_next_page. Tells your worker whether another page exists.NextCursor
JSON field
next_cursor. Store it only when page.HasNextPage is true. For bounded pulls that return fewer tweets than Limit, pass it back as Cursor with the same query, filters, QueryType, and Limit.Tweets as JSON Lines to xquik-tweet-search.jsonl for queues and data lakes, transform the projected records into CSV for analysts, or produce XLSX from those rows when account teams need spreadsheets. Pass ID, Text, Author.Username, CreatedAt, and engagement counts into your CRM or enrichment pipeline. For explicit Limit pulls, resume with the same query, filters, QueryType, and Limit; only Cursor changes.
Workflow: Follower Export to CSV, JSON, or XLSX
Use this workflow when a Go worker needs an owned follower list for a CRM import, warehouse load, analyst CSV file, XLSX workbook, or resumable JSON handoff. It callsPOST /extractions/estimate through client.Extractions.EstimateCost, creates the job with client.Extractions.Run, reads saved rows with client.Extractions.Get, and downloads files with client.Extractions.ExportResults.
client.Extractions.Run returns the queued 202 Accepted receipt from POST /extractions: REST id, toolType, and status: "running" as Go job.ID, job.ToolType, and job.Status. Store job.ID immediately, then poll client.Extractions.Get before reading pages or calling client.Extractions.ExportResults. Credit reservation happens after the job starts. If available credits changed since EstimateCost, the run can fetch only the affordable count before export or mark the job failed with insufficient_credits.follower_explorer requires TargetUsername. Persist job.ID, targetUsername, estimate.EstimatedResults, and estimate.Source before polling so a worker restart can resume the same follower export. client.Extractions.Get returns Results, HasMore, and NextCursor; pass NextCursor back as After when you need stored JSON pages before exporting files. Use xquik-followers.jsonl for queue replay or warehouse loads, xquik-followers.json for app ingestion, xquik-followers.csv for CRM import, and xquik-followers.xlsx for analyst handoff. Map exported User ID or row xUserId as the CRM unique key. Cost: 1 credit per follower extracted or returned. Exports are free after the extraction job exists.
Workflow: Tweet Replies to CSV, JSON, or XLSX
Use this workflow when a Go worker, queue consumer, or agent service needs every reply under one tweet as a saved extraction, JSON Lines handoff, or CSV/JSON/XLSX file export. It callsPOST /extractions/estimate through client.Extractions.EstimateCost, creates the job with client.Extractions.Run, reads rows with client.Extractions.Get, and downloads files with client.Extractions.ExportResults.
Reuse the polling, writeRows, and writeExport helpers from the follower workflow. Only the tool type, target field, and output filenames change:
reply_extractor requires TargetTweetID. client.Extractions.Get returns Results, HasMore, and NextCursor; the shared writeRows helper passes NextCursor back as After until all stored rows are written. Use xquik-replies.jsonl for queue replay or warehouse loads, xquik-replies.json for app ingestion, xquik-replies.csv for CRM import, and xquik-replies.xlsx for analyst handoff. client.Extractions.ExportResults supports CSV, JSON, and XLSX for file handoff. Cost: 1 credit per reply extracted or returned.
Workflow: Post Media Tweets and DM Attachments
Use this workflow when a Go worker, queue consumer, or agent service needs to post a media-backed tweet, reply with media, or send one uploaded media item in a DM. Tweet and reply media posts use public media URLs directly onclient.X.Tweets.New. Send up to 4 image URLs or exactly 1 MP4 video URL up to 100 MB. Do not mix video with other media. Do not upload first when the media URL is already public.
TweetID responses. Use option.WithResponseBodyInto when a write worker must branch on the REST 202 x_write_unconfirmed response, store writeActionId and chargedCredits, and poll Get Write Action Status before sending another write.
ReplyToTweetID:
media.MediaID as the only MediaIDs item:
client.X.Tweets.New returns TweetID for confirmed posts. Raw create responses can also include the pending write fields above when confirmation is still running. client.X.Media.Upload returns media.MediaID for DM attachments, and client.X.Dm.Send returns dm.MessageID for support tickets, CRM records, queue jobs, or agent memory.
Keep DM body text in private systems. Shared logs, public artifacts, queue status, and agent handoffs should store message_id, optional media_id, account, user_id, and send status instead of full DM bodies. Leave ReplyToMessageID unset even if generated SDK params expose it; the REST endpoint rejects DM reply threading.
Text-only tweet and reply writes cost 10 credits. Tweet media adds 2 credits per started MB across attached files. Uploading media costs 10 credits, and sending the DM costs 10 credits. Do not pass uploaded MediaID values to client.X.Tweets.New; that method uses Media with public media URLs.
Cost, Limits & Retries
Tweet search costs 1 credit per tweet returned. If remaining credits cannot cover the requested page, the API can return fewer tweets thanLimit; if 0 paid results are affordable, it returns 402 insufficient_credits. Read calls are rate-limited, and 429 responses include Retry-After.
Generated Go methods return error for connection failures and non-success responses. Retry connection errors, 408, 409, 429, and 5xx responses with backoff. Do not retry 400, 401, 403, 404, or 422 until the request, authentication, permission, or input issue is fixed.
Error Handling
Generated Go methods returnerror for connection failures and non-success API responses. Check the concrete error type from the SDK when you need status-code specific handling, and use the error handling guide for response semantics.
Common retryable cases are connection errors, 408, 409, 429, and 5xx responses.
Pagination
List and search responses expose generated pagination fields such asHasNextPage. Pass cursor parameters from the previous response when the endpoint supports cursor pagination.