PHP code example of raideer / twitch-api

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

    

raideer / twitch-api example snippets


$client = new GuzzleHttp\Client;

$wrapper = new Raideer\TwitchApi\Wrapper($client);

/*
 * Wrapper->resource->function()
 */

$response = $wrapper->Channels->getChannel('lirik');
//OR
$response = $wrapper->resource('channels')->getChannel('lirik');

$wrapper->Channels->getFollows('lirik', ['limit' => 40, 'direction' => 'asc']);

$settings = [
  'client_id'     => 'Your Client ID',
  'client_secret' => 'Your Client Secret',
  'redirect_uri'  => 'Your registered redirect URI',
  'state'         => 'Your provided unique token',
  'scope'         => 'Array or space seperated string of scopes'
];

$oauth = new Raideer\TwitchApi\OAuth($settings);

//Returns the authentication URL
$url = $oauth->getUrl();

$response = $oauth->getResponse($code);

$response->getAccessToken();
$response->getRefreshToken(); //Token refreshing isn't implemented yet
$response->getScope();
$response->hasScope($scope);

//You can pass the OAuthResponse object directly
$wrapper->authorize($response);

//Or just pass the access token
$wrapper->authorize($accessToken);

//Or pass both access token and registered scopes array
$wrapper->authorize($accessToken, $registeredScopes);

$wrapper->Channels->getChannel(); //Returns the authenticated user's channel

$wrapper->enableThrottle(true);

// 1 second throttle
$wrapper->setThrottleInterval(1000);


$client = new GuzzleHttp\Client;
$wrapper = new Raideer\TwitchApi\Wrapper($client);

$settings = [
  'client_id'     => 'myClientId',
  'client_secret' => 'myClientSecret',
  'redirect_uri'  => 'http://localhost',
  'state'         => 'myUniqueToken123123',
  'scope'         => ['channel_editor']
];

$oauth = new Raideer\TwitchApi\OAuth($settings);

// You can also add a scope using the addScope method
$oauth->addScope('channel_read');

$url = $oauth->getUrl();


$code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_STRING);
$response = $oauth->getResponse($code);
$wrapper->authorize($response);

$channel = $wrapper->Channels->getChannel();

echo "I'm currently playing " . $channel->game;