PHP code example of xproapi / xproapi-php

1. Go to this page and download the library: Download xproapi/xproapi-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xproapi / xproapi-php example snippets


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', '

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
json
{
    "repositories": [{ "type": "path", "url": "../xproapi-code-examples/xproapi-php" }],
    "
bash
php tests/run.php