Search by

xquik / x-twitter-scraper

burakbayir

X API & Twitter API SDK for PHP. Scrape Twitter search, profiles & followers as a Twitter scraper & tweet scraper. Not affiliated with X Corp.

v0.14.0 2026-11-18 00:46 UTC

README

Add this X (Twitter) scraper PHP SDK by Xquik to search tweets & posts. Calls take named arguments and return typed value objects. Public reads need no X (Twitter) developer account.

Xquik is the world's fastest and cheapest X (Twitter) scraper service with the most complete X (Twitter) data. Most other Apify Actors charge before filtering or deduplication. Xquik charges only for delivered, unique, filter-matching results and never pads rows. Xquik is independent and not affiliated with X Corp.

The Xquik REST API read 45 tweets per second on 2026-10-15. That cost $0.15 per 1,000. The fastest of 4 rival Actors read 12.5 per second. The cheapest cost $0.173 per 1,000. Compare each run. Most rival Actors charge before they filter or dedup. Xquik charges only for delivered, unique, filter-matching results.

Install the X (Twitter) API PHP SDK

The SDK requires PHP 8.1.0 or later.

Install the Packagist package xquik/x-twitter-scraper with Composer.

composer require xquik/x-twitter-scraper:^0.14.0

Scrape tweets with the Twitter PHP client

Create an API key in the Xquik dashboard and export it.

export X_TWITTER_SCRAPER_API_KEY="your-api-key"

This script prints 10 recent X (Twitter) posts from 1 account.

<?php

require __DIR__ . '/vendor/autoload.php';

use XTwitterScraper\Client;

$client = new Client();

$response = $client->x->tweets->search(q: 'from:elonmusk', limit: 10);

var_dump($response);

Next, read the PHP SDK guide or the REST API reference.

Benchmarks & usage

X (Twitter) API package downloads X (Twitter) API p99 server read time OpenSSF Best Practices

  • 67,000+ downloads of Xquik's X (Twitter) API packages across 6 registries (source)
  • 8.6 s p99 REST server read time over 7 days, failures included (source)
  • This repo meets the OpenSSF Best Practices passing criteria (source)

Checked on 2026-11-13. See each number with its date & source on xquik.com/benchmarks or as JSON.

Common X (Twitter) tasks

Task REST route Usage
Run an advanced Twitter search GET /x/tweets/search Use keywords or supported operators.
Extract an X (Twitter) profile timeline GET /x/users/{id}/tweets Paginate bounded timeline results.
Scrape Twitter followers GET /x/users/{id}/followers Use an extraction for complete datasets.
Scrape X (Twitter) following accounts GET /x/users/{id}/following Use an extraction for complete datasets.
Read a home timeline GET /x/timeline Approve this private read.
Read lists or communities /x/lists/*, /x/communities/* Use the typed nested services.
Export large X (Twitter) datasets POST /extractions Poll status, then download results.
Monitor an account POST /monitors Deliver events through HMAC webhooks.
Post a tweet or reply POST /x/tweets Confirm the account and payload.

Verify a release

Each release attaches a reproducible Composer archive. Replace VERSION with the release number, then rebuild the archive and compare.

release_tag=vVERSION
archive="x-twitter-scraper-php-$release_tag.zip"

git clone --depth 1 --branch "$release_tag" \
  https://github.com/Xquik-dev/x-twitter-scraper-php.git source

gh release download "$release_tag" \
  --repo Xquik-dev/x-twitter-scraper-php \
  --pattern "$archive"

TZ=UTC ./source/scripts/build-archive rebuilt.zip
cmp "$archive" rebuilt.zip

cmp prints nothing when both archives have identical bytes.

Usage

Value objects

Create value objects with named parameters, as in TweetMedia::with(mediaURL: $preview, type: 'photo', url: $url). Builders also work, as in (new TweetMedia)->withURL($url).

Handling errors

Connection failures and non-2xx responses throw an APIException subclass.

<?php

use XTwitterScraper\Core\Exceptions\APIConnectionException;
use XTwitterScraper\Core\Exceptions\RateLimitException;
use XTwitterScraper\Core\Exceptions\APIStatusException;

try {
  $account = $client->account->retrieve();
} catch (APIConnectionException $e) {
  echo "Could not reach the API. Check your connection.", PHP_EOL;
  var_dump($e->getPrevious());
} catch (RateLimitException $e) {
  echo "Rate limit reached. Retry later.", PHP_EOL;
} catch (APIStatusException $e) {
  echo "Request failed. Check the response details.", PHP_EOL;
  echo $e->getMessage();
}

The SDK throws 1 error type for each cause.

Cause Error type
HTTP 400 BadRequestException
HTTP 401 AuthenticationException
HTTP 403 PermissionDeniedException
HTTP 404 NotFoundException
HTTP 409 ConflictException
HTTP 422 UnprocessableEntityException
HTTP 429 RateLimitException
HTTP >= 500 InternalServerException
Other HTTP error APIStatusException
Timeout APITimeoutException
Network error APIConnectionException

Retries

The client retries some failures twice with exponential backoff. It retries connection failures, timeouts and HTTP 408, 409, 429 & 5xx responses. Set maxRetries globally or per request.

<?php

use XTwitterScraper\Client;

// Set the default for all requests.
$client = new Client(requestOptions: ['maxRetries' => 0]);

// Or set it for 1 request.
$result = $client->account->retrieve(requestOptions: ['maxRetries' => 5]);

Custom requests

Pass extraQueryParams, extraBodyParams & extraHeaders through requestOptions. An extra* value overrides its documented counterpart.

<?php

$account = $client->account->retrieve(
  requestOptions: [
    'extraQueryParams' => ['my_query_parameter' => 'value'],
    'extraBodyParams' => ['my_body_parameter' => 'value'],
    'extraHeaders' => ['my-header' => 'value'],
  ],
);

Use $client->request() to keep authentication and retries on undocumented routes.

<?php

$response = $client->request(
  method: 'post',
  path: '/undocumented/endpoint',
  query: ['my_query_parameter' => 'value'],
  headers: ['my-header' => 'value'],
  body: ['my_body_parameter' => 'value'],
);

Versioning

This package follows SemVer. Before version 1.0, APIs may change without a major release. PHPDoc-only type improvements are non-breaking changes.

Questions

Do I need an X (Twitter) developer account?

No. Public reads need only an Xquik API key. Private reads & account actions need a connected X (Twitter) account.

Is this the official X API?

No. Xquik runs its own REST API. This SDK calls that API, not the official X API.

More Xquik tools

Project policies

Read Contributing, Governance, and Security. See OpenSSF evidence for verified controls and blockers.

Xquik is an independent third-party service. Not affiliated with X Corp. "Twitter" and "X" are trademarks of X Corp.