Use the PHP SDK for PHP 8.1+ applications with named parameters, generated models, typed exceptions, retries, and file upload helpers. It is useful when a PHP app or worker needs to search tweets, scrape tweets or replies to JSON Lines, CSV, or XLSX, export followers, monitor tweets, post media tweets, upload media, send direct messages, or hand X API data to a queue, CRM, or reporting pipeline.Documentation Index
Fetch the complete documentation index at: https://docs.xquik.com/llms.txt
Use this file to discover all available pages before exploring further.
Install
composer.json as described in the source repository.
Authenticate
Basic Example
Search tweets and write durable JSON Lines handoff rows:Workflow: Search Tweets to JSON Lines, CSV, or XLSX
Use this workflow when a PHP worker, Laravel command, Symfony console command, or cron job needs tweet search results in a durable file for a queue, warehouse loader, analyst CSV export, XLSX workbook, or CRM enrichment step.$client->x->tweets->search() calls GET /x/tweets/search. The generated parameter model is TweetSearchParams, and the service method exposes the same request controls as named arguments: q, limit, cursor, sinceTime, untilTime, and queryType.
Request Mapping
q
PHP argument
q maps to REST q. Use it for an X search query such as from:username, a keyword, hashtag, or boolean operator query.limit
PHP argument
limit maps to REST limit. Use it for a bounded request from 1 to 200. Omit it for cursor loops.cursor
PHP argument
cursor maps to REST cursor. Pass the opaque cursor from $page->nextCursor to request the next page.sinceTime
PHP argument
sinceTime maps to REST sinceTime. Use it as the ISO 8601 lower bound for tweet creation time.untilTime
PHP argument
untilTime maps to REST untilTime. Use it as the ISO 8601 upper bound for tweet creation time.queryType
PHP argument
queryType maps to REST queryType. Use QueryType::LATEST for chronological search or QueryType::TOP for engagement-ranked search.Returned Data & Handoff
$client->x->tweets->search() returns PaginatedTweets. Use $page->tweets for the tweet array, $page->hasNextPage to decide whether another page exists, and $page->nextCursor as the checkpoint for the next request.
Each SearchTweet includes typed properties such as $id, $text, $author, $createdAt, $likeCount, $replyCount, $retweetCount, $quoteCount, $bookmarkCount, $viewCount, and $isNoteTweet when available. Project $page->tweets into JSON Lines and CSV rows with tweet_id, author_username, engagement counts, page_index, page_cursor, next_cursor, and has_next_page so workers can resume safely or load the same records into XLSX, CRM, warehouse, or agent workflows.
Tweet search costs 1 credit per tweet returned. If remaining credits cannot cover a bounded limit request, the API can return fewer tweets; if 0 paid results are affordable, it returns 402 insufficient_credits. The SDK retries connection errors, timeouts, 408, 409, 429, and 5xx responses 2 times by default. For long-running workers, pass requestOptions: ['maxRetries' => 5] and persist $page->nextCursor after each page.
Workflow: Follower Export to CSV, JSON, or XLSX
Use this workflow when a PHP worker, Laravel command, Symfony console command, or cron job needs an owned follower list for CRM import, warehouse loading, account scoring, analyst CSV, XLSX delivery, or a resumable JSON handoff.$client->extractions->estimateCost() maps to POST /extractions/estimate, $client->extractions->run() maps to POST /extractions, $client->extractions->retrieve() maps to GET /extractions/{id}, and $client->extractions->exportResults() maps to GET /extractions/{id}/export. For follower exports, follower_explorer requires targetUsername.
$job->id, $targetUsername, $estimate->estimatedResults, and $estimate->source before polling so another queue worker can resume without rerunning the extraction. $client->extractions->retrieve() returns $page->results, $page->hasMore, and $page->nextCursor; pass $page->nextCursor back as after to page through large follower lists. Map exported User ID or row xUserId as the CRM unique key. 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. 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 PHP worker needs every reply on a public tweet in a durable file for moderation review, customer support triage, analyst export, or a warehouse loader.$client->extractions->estimateCost() and $client->extractions->run() map to the extraction workflow. For tweet replies, use ToolType::REPLY_EXTRACTOR; reply_extractor requires targetTweetID. $client->extractions->retrieve() returns results, hasMore, and nextCursor for pagination. $client->extractions->exportResults() returns the completed job as a string and supports CSV, JSON, and XLSX export formats.
$job->id on the queue job, ticket, or warehouse batch before polling so another worker can resume with $client->extractions->retrieve(). Keep $page->nextCursor as the checkpoint when you stream replies to JSON Lines. 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.
Workflow: Post Media Tweets and DM Attachments
Use this workflow when a PHP app needs to publish a media tweet, reply with media, or send a direct message with an uploaded local file.POST /x/tweets accepts public media URLs through media. Send up to 4 image URLs or exactly 1 MP4 video URL up to 100 MB, and do not mix video with other media. For replies, set replyToTweetID to the parent tweet ID. $client->x->media->upload() maps to POST /x/media; use its $media->mediaID only for the one-item mediaIDs array on $client->x->dm->send().
Use $client->x->tweets->raw->create() when a worker must branch on the REST 202 x_write_unconfirmed response. The generated $client->x->tweets->create() helper is still useful when your flow only continues after a confirmed $tweet->tweetID.
write_action_id and charged_credits, then poll Get Write Action Status before retrying a pending tweet or reply. Store tweet_id on the CMS, queue job, or agent state after confirmed writes. Store $dm->messageID on the support ticket or CRM note. 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 $media->mediaID values to $client->x->tweets->create(); that method uses media with public media URLs.
Error Handling
The SDK throws subclasses ofXTwitterScraper\Core\Exceptions\APIException.
400 Bad Request
Throws
BadRequestException.401 Unauthorized
Throws
AuthenticationException.403 Permission Denied
Throws
PermissionDeniedException.404 Not Found
Throws
NotFoundException.422 Validation Error
Throws
UnprocessableEntityException.429 Rate Limited
Throws
RateLimitException.5xx Server Error
Throws
InternalServerException.Pagination
Paginated responses expose fields such ashasNextPage. Pass the endpoint’s cursor fields when requesting more pages.