PHP code example of nullform / tgstat-client

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

    

nullform / tgstat-client example snippets


use Nullform\TGStatClient;

$client = new TGStatClient\Client($token);
$client->sandbox(true);
$client->timeout(10);
$client->userAgent('TGStatClient');

try {
    // API request statistics
    $usage_stat = $client->callUsageStat();
} catch (\Exception $exception) {
    $error = $exception->getMessage();
}

$usage_stat = $client->callUsageStat();

$params = new TGStatClient\Params\PostsSearchParams();

$params->q = 'Jazz | "Jazz music"'; // Extended syntax
$params->hideDeleted = 1;
$params->peerType = 'channel';
$params->extended = 1;
$params->extendedSyntax = 1;
$params->limit = 3;

$posts = $client->callPostsSearch($params);

$params = new TGStatClient\Params\WordsMentionsByChannelsParams();

$params->q = 'Jazz music';
$params->strongSearch = 1;

$mentions = $client->callWordsMentionsByChannels($params);

$request = $client->lastRequest();

$status = $client->lastResponse()->status;
$http_status = $client->lastResponse()->getHttpStatus();
$is_from_cache = $client->lastResponse()->from_cache;

if ($client->lastResponse()->getError()) {
    $error = $client->lastResponse()->getError()->message;
}

// Set PSR-6 or PSR-16 cache instance, TTL (60) and cache keys prefix (tgstat_client_)
$client->caching($cache, 60, 'tgstat_client_');

$log_func = function (TGStatClient\Client $client) {
    file_put_contents('tgstat-client-log.log', print_r($client->lastResponse(), true));
};

$client = new TGStatClient\Client($token);
$client->logFunction($log_func);

$stat = $client->callUsageStat();