<?php

require '../vendor/autoload.php';
require 'config.php';
use Redbox\Twitch;
$twitch = new Redbox\Twitch\Client();
$resources = $twitch->getSupportedFunctions();
// FIXME broken!
?>

<style type="text/css">
    table th { padding: 6px 13px;  border: 1px solid #ddd; font-weight: bold; }
    table td { padding: 6px 13px;  border: 1px solid #ddd;}
    pre { background-color: rgba(0,0,0,0.04); display: inline-block; padding: 6px 13px; }
</style>
<?php 
foreach ($resources as $resource_name => $resource) {
    ?>
    <h1>Resource <?php 
    echo strtoupper($resource_name);
    ?>
</h1>
    <?php 
    $resource_path = $resource->getResourcePath();
    $resource_name = $resource_name;
    $methods = $resource->getMethods();
    foreach ($methods as $method_name => $method) {
        echo '<h2>Method ->' . $method_name . '()</h2>';
        echo '<pre>Requires authorization: ' . ($method['requiresAuth'] ? 'Yes' : 'No') . '</pre>';
        if (count($method['parameters']) > 0) {
            echo '<h3>Parameters</h3>';
<?php

require '../vendor/autoload.php';
require 'config.php';
use Redbox\Twitch;
error_reporting(E_ALL);
ini_set('display_errors', true);
try {
    echo '<h1>Welcome back</h1>';
    if (isset($_GET['code']) === true and isset($_GET['state']) === true) {
        $code = htmlentities($_GET['code']);
        $state = htmlentities($_GET['state']);
        if ($state != session_id()) {
            die('Computer says noooo.');
        }
        $twitch = new Redbox\Twitch\Client();
        $twitch->setClientId($config['twitch_client_id'])->setClientSecret($config['twitch_client_secret'])->setRedirectUri($config['twitch_redirect_uri'])->setForceRelogin($config['twitch_force_login']);
        if ($response = $twitch->auth->requestAccessToken($code, $state)) {
            $_SESSION['access_token'] = $response->getAccessToken();
            $_SESSION['scope'] = $response->getScope();
            echo 'It looks like it all worked out. <a href="get-root.php">Check how get-root looks like now</a> OR <a href="authorize-user.php">Check if your authenticated in authorize-user.php</a>';
        } else {
            die('Die oops something wend wrong.');
        }
    } else {
        if (isset($_SESSION['access_token']) === true) {
            echo 'It looks like it all worked out. <a href="get-root.php">Check how get-root looks like now</a> OR <a href="authorize-user.php">Check if your authenticated in authorize-user.php</a>';
        } else {
            echo '<h1>Oops something went wrong</h1>';
        }
    }
<?php

require '../vendor/autoload.php';
require 'config.php';
use Redbox\Twitch;
use Redbox\Twitch\Scope;
try {
    $channel_id = 'ign';
    if (isset($_GET['id']) === true) {
        $channel_id = htmlentities($_GET['id']);
    }
    $twitch = new Redbox\Twitch\Client();
    if (isset($_SESSION['access_token']) === true) {
        $twitch->setAccessToken($_SESSION['access_token']);
        $twitch->setScope($_SESSION['scope']);
    }
    $channel = $twitch->channels->getChannelEditors(array('channel' => $channel_id));
    print '<pre>';
    print_r($channel);
} catch (Exception $e) {
    print '<pre>';
    print_r($e);
}
Ejemplo n.º 4
0
<?php

require '../vendor/autoload.php';
require 'config.php';
use Redbox\Twitch;
// Note this function requires the user to be authenticated.
try {
    $user = '******';
    if (isset($_GET['username']) === true) {
        $user = htmlentities($_GET['username']);
    }
    $twitch = new Redbox\Twitch\Client();
    if (isset($_SESSION['access_token']) === true) {
        $twitch->setAccessToken($_SESSION['access_token']);
    }
    $user = $twitch->users->getUser();
    echo '<pre>';
    print_r($user);
} catch (Exception $e) {
    print '<pre>';
    print_r($e);
}
Ejemplo n.º 5
0
<?php

require '../vendor/autoload.php';
require 'config.php';
use Redbox\Twitch;
use Redbox\Twitch\Scope;
$twitch = new Redbox\Twitch\Client();
$twitch->setClientId($config['twitch_client_id'])->setClientSecret($config['twitch_client_secret'])->setRedirectUri($config['twitch_redirect_uri'])->setForceRelogin($config['twitch_force_login']);
if (isset($_SESSION['access_token']) === true) {
    $twitch->setAccessToken($_SESSION['access_token']);
}
// TODO change to getRoot()
$token = $twitch->root->getRoot();
/**
 * State is for defending XSS attacks.
 * It is optional for createAuthUrl() but it is a good practice to use it.
 *
 * Also note that if you use it don't forget to check the value (see authorize-returning-user.php).
 */
$state = session_id();
// TODO check without state if the flow still works ..
$url = $twitch->getAuthModel()->createAuthUrl(Scope::generate(array(Scope::SCOPE_USER_READ, Scope::CHANNEL_READ)), $state);
if ($token->isValid() === false) {
    echo 'You are not authorized, you should click <a href="' . $url . '">This link</a> to authorize your self. Please note you will not return to this script in fact you will return to ' . $config['twitch_redirect_uri'];
} else {
    echo 'You are correctly authorized';
}
<?php

require '../vendor/autoload.php';
require 'config.php';
use Redbox\Twitch;
/**
 * Please note: This method requires the user to be authenticated.
 */
try {
    $twitch = new Redbox\Twitch\Client();
    if (isset($_SESSION['access_token']) === true) {
        $twitch->setAccessToken($_SESSION['access_token']);
    }
    $twitch->setClientId($config['twitch_client_id'])->setClientSecret($config['twitch_client_secret'])->setRedirectUri($config['twitch_redirect_uri'])->setForceRelogin($config['twitch_force_login']);
    $videos = $twitch->videos->listVideosFollowed(array('offset' => 10, 'limit' => 1));
    ?>
    <h1>List videos from users i am following</h1>
    <?php 
    echo '<ul>';
    foreach ($videos as $video) {
        echo '<li><img src="' . $video->getPreview() . '" /> ' . $video->getTitle() . '</li>';
    }
    echo '</ul>';
} catch (Redbox\Twitch\Exception\AuthorizationRequiredException $e) {
    print '<pre>';
    print_r($e);
} catch (Exception $e) {
    print '<pre>';
    print_r($e);
}