Skip to main content

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.

Use the PHP SDK for PHP 8.1+ applications with named parameters, generated models, typed exceptions, retries, and file upload helpers.

Install

composer require xquik/x-twitter-scraper
If your project needs the GitHub source directly, add the repository in composer.json as described in the source repository.

Authenticate

export X_TWITTER_SCRAPER_API_KEY="xq_YOUR_KEY_HERE"

Basic Example

<?php

use XTwitterScraper\Client;

$client = new Client(
  apiKey: getenv('X_TWITTER_SCRAPER_API_KEY') ?: 'xq_YOUR_KEY_HERE'
);

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

var_export($tweets->has_next_page);

Error Handling

The SDK throws subclasses of XTwitterScraper\Core\Exceptions\APIException.
StatusException
400BadRequestException
401AuthenticationException
403PermissionDeniedException
404NotFoundException
422UnprocessableEntityException
429RateLimitException
5xxInternalServerException
<?php

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

try {
  $account = $client->account->retrieve();
} catch (APIConnectionException $e) {
  fwrite(STDERR, "Connection failed\n");
} catch (APIStatusException $e) {
  fwrite(STDERR, $e->getMessage() . PHP_EOL);
}

Pagination

Paginated responses expose fields such as has_next_page. Pass the endpoint’s cursor fields when requesting more pages.
<?php

$page = $client->x->tweets->search(q: 'xquik', limit: 20);

if ($page->has_next_page) {
  fwrite(STDERR, "More results are available\n");
}

Webhooks & References