PHP code example of scrapingisnotacrime / sdk

1. Go to this page and download the library: Download scrapingisnotacrime/sdk 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/ */

    

scrapingisnotacrime / sdk example snippets


use ScrapingIsNotACrime\Client;
use ScrapingIsNotACrime\Exception\NotFoundException;

$client = new Client(apiKey: 'sinac_...');

try {
    $profile = $client->instagram->profile('nasa');
    echo $profile->username, ' ', $profile->followers, PHP_EOL;
} catch (NotFoundException) {
    echo 'no such profile', PHP_EOL;
}

$client = new Client(
    apiKey: 'sinac_...',
    baseUrl: 'https://api.scrapingisnotacrime.com/v1',
    timeout: 30.0,
    maxRetries: 2,
    httpClient: null,
    requestFactory: null,
);

use GuzzleHttp\Client;
use ScrapingIsNotACrime\Client as ScrapingIsNotACrimeClient;

$client = new ScrapingIsNotACrimeClient(
    apiKey: 'sinac_...',
    httpClient: new Client([
        'timeout' => 30,
        'allow_redirects' => false,
        // 'proxy' => 'http://localhost:8080',
    ]),
);

use ScrapingIsNotACrime\Client as ScrapingIsNotACrimeClient;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\Psr18Client;

$client = new ScrapingIsNotACrimeClient(
    apiKey: 'sinac_...',
    httpClient: new Psr18Client(HttpClient::create([
        'timeout' => 30,
        'max_duration' => 30,
        'max_redirects' => 0,
        // 'proxy' => 'http://localhost:8080',
    ])),
);

final class Page implements \IteratorAggregate
{
    public readonly array $items;      // this page's items, already decoded
    public readonly bool $hasMore;
    public readonly ?string $nextCursor; // cursor endpoints; null when there is none
    public readonly ?int $nextPage;      // page-number endpoints; null when there is none
    public readonly object $data;        // this page's typed page object (e.g. GithubUserPage), with fields like ->total

    public function next(): ?self; // fetches the following page; null when there is none
    public function getIterator(): \Generator; // yields items across pages, lazily
}

$page = $client->bluesky->posts('bsky.app', limit: 25);
$fetched = 0;
while ($page !== null && $fetched < 3) {
    foreach ($page->items as $post) {
        echo $post->text, PHP_EOL;
    }
    $page = $page->next();
    $fetched++;
}

$page = $client->github->followers('torvalds', limit: 100);
$count = 0;
foreach ($page as $user) {
    echo $user->username, PHP_EOL;
    if (++$count >= 250) {
        break; // stop early; no further pages are fetched
    }
}

use ScrapingIsNotACrime\Exception\NotFoundException;
use ScrapingIsNotACrime\Exception\QuotaExceededException;
use ScrapingIsNotACrime\Exception\RateLimitException;
use ScrapingIsNotACrime\Exception\ScrapingIsNotACrimeException;

try {
    $profile = $client->tiktok->profile('this-user-does-not-exist-123');
    echo $profile->username, PHP_EOL;
} catch (NotFoundException) {
    echo 'no such profile', PHP_EOL;
} catch (QuotaExceededException $e) {
    throw $e; //