Skip to content

Commit

Permalink
Merge pull request #6 from cp6/Extras
Browse files Browse the repository at this point in the history
v1.1
  • Loading branch information
cp6 authored Aug 14, 2021
2 parents d6b5a07 + 29333b7 commit 51c1fcb
Show file tree
Hide file tree
Showing 7 changed files with 411 additions and 364 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
78 changes: 57 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,52 @@ This class will automatically refresh access token once it expires!
* Get users clips
* Get game name for game id
* Get game artwork for game id
* PHP 8

## Usage

Add your Twitch client id, client secret and authorization code into the constants (lines 5-7)
**Fetch with composer:**

Add your redirect URI [info](https://write.corbpie.com/twitch-api-authentication-with-oauth-using-php/) (line 8)
```shell
composer require corbpie/twitch-api-class
```

Change the token filename constant, however keep it as a .txt extension (line 9)
To use:

Make sure the class file is included
```php
require_once('twitch-class.php');
require_once('vendor/autoload.php');

use Corbpie\TwitchApiClass\twitchWrapper;

$call = new twitchWrapper();
```

Then assign a new instance
Add your Twitch client id and client secret into the constants (lines 7-8)

Add your redirect URI [info](https://write.corbpie.com/twitch-api-authentication-with-oauth-using-php/) (line 10)

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

Access code can be obtained with

```php
$call = new twitch_call();
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`

```php
$call->getTopStreams();
```

<b>Protect your calls against an expired access token:</b>

```php
$data = $call->getUserLiveData('summit1g');
if (!$call->checkCallSuccess($data)) {//Call failed but refreshed token, try it again:
Expand All @@ -67,17 +88,20 @@ echo $data;
```

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

```php
$call->getGameTopStreams($gameid);
```

Get top (view count) streamer for a game `string`

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

Get viewer count for the top stream for a game `string`

```php
$call->getGameTopStreams($gameid);
echo $call->getTopViewersForGame();
Expand All @@ -86,141 +110,153 @@ echo $call->getTopViewersForGame();
Get top games `array`

(Good way to get gameid's)

```php
$call->getTopGames();
```

Get details for username `array`

```php
$call->getUserDetails($username);
```

Get user id for username `string`

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

Get emotes for username `array`

```php
$call->getUserEmotes($username);
```

Get image for emote id `string`

```php
$call->emoteImage($emoteid);
```


Get chat for VOD `array`

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


Get users stream details (If live) `array`

```php
$call->getUserStream($username);
```

Check if a user is live and streaming `boolean`

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

__If user is streaming:__

Get game id `string`

```php
$call->streamGameId();
```

Get viewer count `string`

```php
$call->streamViewers();
```

Get stream title `string`

```php
$call->streamTitle();
```

Get stream id `string`

```php
$call->streamId();
```

Get stream start time `string`

```php
$call->streamStart();
```

Get stream thumbnail `string`

```php
$call->streamThumbnail();
```

Get stream thumbnail `array`

```php
$call->getStreamTags($streamid);
```

Get top clips for game id `array`

```php
$call->getGameClips($gameid);
```

Get users top clips `array`

```php
$call->getUserClips($user);
```

Get users videos (most recent first) `array`

```php
$call->getUserVideos($user);
```

Get users videos for game id `array`

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

Get game data for game id `array`

```php
$call->getGameData($game_id);
```

Get game name `string`

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

Get game artwork `string`

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

Get game artwork `string`

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

Set JSON header
```php
$call->setJsonHeader();
```

Custom array access `string`

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


## TODO

* Access to all values, not just popular ones.
* Greater options to calls, add filter types (Newest, view count, length).
```
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "corbpie/twitch-api-class",
"description": "A PHP Twitch API wrapper",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"Corbpie\\TwitchApiClass\\": "src/"
}
},
"authors": [
{
"name": "corbpie",
"email": "contact@corbpie.com"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=8.0",
"ext-curl": "*"
}
}
20 changes: 20 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
require_once('twitch-class.php');

$call = new twitch_call();
$call->setApiKey('TWITCHCLIENTID');//Set client id
$call->getUserStream('shroud');//Set streamers username
if ($call->userIsLive()) {//Will return true is user is live/streaming
echo "Shroud is streaming right now";
}
require_once('vendor/autoload.php');

use Corbpie\TwitchApiClass\twitchWrapper;

$call = new twitchWrapper();

echo $call->accessCodeUrl();

echo json_encode($call->getUserDetails('shroud'));
Loading

0 comments on commit 51c1fcb

Please sign in to comment.