PHP code example of twitchphp / http

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

    

twitchphp / http example snippets


use React\EventLoop\Loop;
use Twitch\Http\Endpoint;
use Twitch\Http\Http;
use Twitch\Http\OAuth;

$loop = Loop::get();
$oauth = new OAuth('client-id', 'client-secret', $loop);

$oauth->clientCredentials()->then(function (array $token) use ($loop) {
    $http = Http::create($token['access_token'], 'client-id', null, $loop);

    // GET https://api.twitch.tv/helix/users?login=twitchdev
    $http->get(
        (new Endpoint(Endpoint::USERS))->addQuery('login', 'twitchdev')
    )->then(function (?array $body) {
        // $body === ['data' => [[...user...]], 'pagination' => []]
        print_r($body['data'][0]);
    });
});

$loop->run();