PHP code example of obnoxiousfrog / twitch-api

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

    

obnoxiousfrog / twitch-api example snippets


 {

	$auth = new TwitchApi\Authenticator(new TwitchApi\Application(
		'3nyv5fcqdpg8uakewz6mj27r49xhbs',
		'aqdrje795sh4nm2fk8btpwuvy3cg6z',
		['user_read', 'user_subscriptions'],
		'https://www.domain.tld/authenticate'
	));
	
	if ( ! $auth->authenticate() or ! ($user = $auth->user()))
	{
		throw new Exception('Oops, something went wrong!');
	}
	
	if ( ! $user->isFollowing('obnoxiousfrog'))
	{
		throw new Exception('You are not a follower of ObnoxiousFrog!');
	}
	
	if ( ! $user->isSubscribed('obnoxiousfrog'))
	{
		throw new Exception('You are not a subscriber of ObnoxiousFrog!');
	}
	
	echo 'Welcome, '.$user->displayname().'!';

} catch (Exception $e) {
	// Log error
}

$twitch = new TwitchApi\Application('client', 'secret', ['scopes'], 'redirect');

$twitch = new TwitchApi\Application(
	'3nyv5fcqdpg8uakewz6mj27r49xhbs',
	'aqdrje795sh4nm2fk8btpwuvy3cg6z',
	['user_read', 'user_subscriptions'],
	'https://www.domain.tld/authenticate',
);

$auth = new TwitchApi\Authenticator($twitch);

$twitch->bind('TwitchApi\Contracts\User', 'CustomUserClass');