Skip to content

Feature-packed PHP class for the latest Twitch API

Notifications You must be signed in to change notification settings

cp6/Twitch-API-class

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twitch API class

Updated for OAuth usage!

Feature packed, easy to use PHP class for the latest Twitch API.

You will need your free Twitch client id to use, see here to obtain.

To get your authorization code see here.

This class will automatically refresh access token once it expires!

Features

  • Get top streams
  • Get top streams for game
  • Get popular games
  • Get details for username
  • Get user id for username
  • Get users emotes
  • Get emote image
  • Get chat for a VOD
  • Check if user is live
  • Get users streaming game
  • Get users streaming title
  • Get users streaming id
  • Get streaming thumbnail
  • Get users view count
  • Get users streaming description
  • Get users stream start time
  • Get users stream tags
  • Get clips for game
  • Get users clips
  • Get game name for game id
  • Get game artwork for game id

Usage

Fetch with composer:

composer require corbpie/twitch-api-class

To use:

require_once('vendor/autoload.php');

use Corbpie\TwitchApiClass\twitchWrapper;

$call = new twitchWrapper();

Add your Twitch client id and client secret into src/twitchWrapper.php (lines 7-8)

Add your redirect URI info (line 10)

Change the token filename constant, however keep it as a .txt extension (line 11)

Access code can be obtained with

echo $call->accessCodeUrl();

Upon going to the link You will find the access code in the URL:

http://localhost/?code=THEISACCESSCODE

Calls

Get current top (view count) streams array

$call->getTopStreams();

Get current top (view count) streams for a game array

$call->getGameTopStreams($gameid);

Get top (view count) streamer for a game string

$call->getGameTopStreams($gameid);
echo $call->getTopStreamerForGame();

Get viewer count for the top stream for a game string

$call->getGameTopStreams($gameid);
echo $call->getTopViewersForGame();

Get top games array

(Good way to get gameid's)

$call->getTopGames();

Get details for username array

$call->getUserDetails($username);

Get user id for username string

$call->getUserDetails($username);
$user_id = $call->idForUser();

Get emotes for username array

$call->getUserEmotes($username);

Get image for emote id string

$call->emoteImage($emoteid);

Get chat for VOD array

$call->chatForVod($vod_id, $offset);

Get users stream details (If live) array

$call->getUserStream($username);

Check if a user is live and streaming boolean

$call->getUserStream($username);
$call->userIsLive();//true for live | false for not live

If user is streaming:

Get game id string

$call->streamGameId();

Get viewer count string

$call->streamViewers();

Get stream title string

$call->streamTitle();

Get stream id string

$call->streamId();

Get stream start time string

$call->streamStart();

Get stream thumbnail string

$call->streamThumbnail();

Get stream thumbnail array

$call->getStreamTags($streamid);

Get top clips for game id array

$call->getGameClips($gameid);

Get users top clips array

$call->getUserClips($user);

Get users videos (most recent first) array

$call->getUserVideos($user);

Get users videos for game id array

$call->getUserVideosForGame($user, $game_id);

Get game data for game id array

$call->getGameData($game_id);

Get game name string

$call->getGameData($game_id);
$game_name = $call->gameName();

Get game artwork string

$call->getGameData($game_id);
$game_name = $call->gameArtwork();

Get game artwork string

$call->getGameData($game_id);
$game_name = $call->gameArtwork();

Custom array access string

//array return call here Eg:$call->getUserDetails('shroud');
$custom = $call->getCustom(0, 'type');

About

Feature-packed PHP class for the latest Twitch API

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages