The official PHP SDK for Xproapi.com. A lightweight, type-safe client designed to query public X (Twitter) profiles, track follower events, and detect network diffs without heavy enterprise API costs or streaming connection overhead.
- Follower Event Tracking: Fetch latest follower pages and compute diffs reliably.
- Profile & Graph Ingestion: Access public follower and following lists as structured objects.
- Resilient Network Handling: Built-in rate limit (HTTP 429) backoff, automatic retries, and strict timeouts.
- Framework Agnostic: Works seamlessly in vanilla PHP, Laravel, Symfony, or background CLI workers.
Requires PHP 8.1+ with ext-curl and ext-json; no other dependencies.
With Composer, from this folder (a path repository):
{
"repositories": [{ "type": "path", "url": "../xproapi-code-examples/xproapi-php" }],
"require": { "xproapi/xproapi-php": "*" }
}Without Composer, copy the folder and require 'xproapi-php/autoload.php';.
use Xproapi\Client;
$x = new Client(getenv('XPROAPI_KEY'));
$user = $x->userInfo('jack')['data'];
echo "{$user['name']} has {$user['followers']} followers\n";
// One page (up to 200)
$page = $x->followers('jack', pageSize: 200);
foreach ($page['followers'] as $follower) { /* ... */ }
$next = $x->followers('jack', cursor: $page['next_cursor']);
// Every page, capped at 5 requests
foreach ($x->paginate('followers', ['userName' => 'jack'], maxPages: 5) as $follower) {
echo $follower['userName'], "\n";
}
// Tweets
$x->lastTweets(['userName' => 'jack', 'includeReplies' => false]);
$x->advancedSearch('from:jack min_faves:100', queryType: 'Top');
$x->tweetsByIds(['20', '1800000000000000000']);
$x->replies('https://x.com/jack/status/20'); // ids or linksMethods return the API's JSON as arrays. The response keys are listed in the root README.
new Client(
apiKey: 'xp_...',
baseUrl: 'https://xproapi.com/api', // default
timeout: 30, // seconds per request
maxRetries: 2, // for 429 / 502 / 503 / network errors; 0 = off
);use Xproapi\{InsufficientCreditsException, NotFoundException, RateLimitException, XproapiException};
try {
$x->userInfo('someone');
} catch (NotFoundException) {
// no such user
} catch (InsufficientCreditsException $e) {
// top up; nothing was charged
} catch (RateLimitException $e) {
sleep($e->retryAfter);
} catch (XproapiException $e) {
error_log("Xproapi {$e->status}: {$e->getMessage()}");
}$x->rateLimit(); // ['limit' => 60, 'remaining' => 57] from the last response$x->get('/twitter/user/info', ['userName' => 'jack']) calls any GET endpoint with the same auth, retries and errors.
php tests/run.php