Skip to main content
This guide builds on the PHP SDK setup, which covers install and authentication.

Tweet search workflow to JSON Lines, CSV, or XLSX

Use this workflow when PHP code needs tweet search results in a durable file. That code can be a worker, Laravel command, Symfony console command, or cron job. The file can feed a queue, warehouse loader, or analyst CSV export. It can also feed an XLSX workbook or a CRM enrichment step. $client->x->tweets->search() calls GET /x/tweets/search. The generated parameter model is TweetSearchParams. The service method exposes the same request controls as named arguments. They are q, limit, cursor, sinceTime, untilTime, and queryType.

Request mapping

q

PHP argument q maps to REST q. It takes an X (Twitter) search query. Examples are from:username, a keyword, hashtag, or boolean operator query.

limit

PHP argument 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. That applies when you continue with $page->nextCursor.

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 the inclusive ISO bound on every page.

untilTime

PHP argument untilTime maps to REST untilTime. Use the exclusive ISO bound on every page.

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 tells you whether another page exists. Use $page->nextCursor as the checkpoint for the next request. For bounded pulls that return fewer tweets than limit, pass $page->nextCursor back as cursor. Send the same query, filters, queryType, and limit with it.Each SearchTweet includes typed properties such as $id, $text, $author, and $createdAt. It also includes $likeCount, $replyCount, $retweetCount, $quoteCount, $bookmarkCount, $viewCount, and $isNoteTweet when available. Project $page->tweets into JSON Lines and CSV rows. Each row holds tweet_id, author_username, engagement counts, page_index, page_cursor, next_cursor, and has_next_page. Workers can then resume. Or they can load the same records into XLSX, CRM, warehouse, or agent workflows.Tweet search costs 1 credit per tweet returned. If credits cannot cover a bounded limit request, the API can return fewer tweets. If credits cover 0 results, it returns 402 insufficient_credits. The SDK retries connection errors, timeouts, 408, 409, 429, and 5xx responses by default. The default is 2 retries. For explicit limit pulls, resume with the same query, filters, queryType, and limit. Only cursor changes.

Next steps