Skip to content

Commit 29333b7

Browse files
committed
v1.1
v1.1
1 parent c8ed550 commit 29333b7

File tree

7 files changed

+411
-364
lines changed

7 files changed

+411
-364
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

README.md

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,52 @@ This class will automatically refresh access token once it expires!
3333
* Get users clips
3434
* Get game name for game id
3535
* Get game artwork for game id
36+
* PHP 8
3637

3738
## Usage
3839

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

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

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

45-
Make sure the class file is included
4648
```php
47-
require_once('twitch-class.php');
49+
require_once('vendor/autoload.php');
50+
51+
use Corbpie\TwitchApiClass\twitchWrapper;
52+
53+
$call = new twitchWrapper();
4854
```
4955

50-
Then assign a new instance
56+
Add your Twitch client id and client secret into the constants (lines 7-8)
57+
58+
Add your redirect URI [info](https://write.corbpie.com/twitch-api-authentication-with-oauth-using-php/) (line 10)
59+
60+
Change the token filename constant, however keep it as a .txt extension (line 11)
61+
62+
Access code can be obtained with
63+
5164
```php
52-
$call = new twitch_call();
65+
echo $call->accessCodeUrl();
5366
```
5467

68+
Upon going to the link You will find the access code in the URL:
69+
70+
```http://localhost/?code=THEISACCESSCODE```
71+
72+
### Calls
73+
5574
Get current top (view count) streams `array`
75+
5676
```php
5777
$call->getTopStreams();
5878
```
5979

6080
<b>Protect your calls against an expired access token:</b>
81+
6182
```php
6283
$data = $call->getUserLiveData('summit1g');
6384
if (!$call->checkCallSuccess($data)) {//Call failed but refreshed token, try it again:
@@ -67,17 +88,20 @@ echo $data;
6788
```
6889

6990
Get current top (view count) streams for a game `array`
91+
7092
```php
7193
$call->getGameTopStreams($gameid);
7294
```
7395

7496
Get top (view count) streamer for a game `string`
97+
7598
```php
7699
$call->getGameTopStreams($gameid);
77100
echo $call->getTopStreamerForGame();
78101
```
79102

80103
Get viewer count for the top stream for a game `string`
104+
81105
```php
82106
$call->getGameTopStreams($gameid);
83107
echo $call->getTopViewersForGame();
@@ -86,141 +110,153 @@ echo $call->getTopViewersForGame();
86110
Get top games `array`
87111

88112
(Good way to get gameid's)
113+
89114
```php
90115
$call->getTopGames();
91116
```
92117

93118
Get details for username `array`
119+
94120
```php
95121
$call->getUserDetails($username);
96122
```
97123

98124
Get user id for username `string`
125+
99126
```php
100127
$call->getUserDetails($username);
101128
$user_id = $call->idForUser();
102129
```
103130

104131
Get emotes for username `array`
132+
105133
```php
106134
$call->getUserEmotes($username);
107135
```
108136

109137
Get image for emote id `string`
138+
110139
```php
111140
$call->emoteImage($emoteid);
112141
```
113142

114-
115143
Get chat for VOD `array`
144+
116145
```php
117146
$call->chatForVod($vod_id, $offset);
118147
```
119148

120-
121149
Get users stream details (If live) `array`
150+
122151
```php
123152
$call->getUserStream($username);
124153
```
125154

126155
Check if a user is live and streaming `boolean`
156+
127157
```php
128158
$call->getUserStream($username);
129159
$call->userIsLive();//true for live | false for not live
130160
```
161+
131162
__If user is streaming:__
132163

133164
Get game id `string`
165+
134166
```php
135167
$call->streamGameId();
136168
```
137169

138170
Get viewer count `string`
171+
139172
```php
140173
$call->streamViewers();
141174
```
142175

143176
Get stream title `string`
177+
144178
```php
145179
$call->streamTitle();
146180
```
147181

148182
Get stream id `string`
183+
149184
```php
150185
$call->streamId();
151186
```
152187

153188
Get stream start time `string`
189+
154190
```php
155191
$call->streamStart();
156192
```
157193

158194
Get stream thumbnail `string`
195+
159196
```php
160197
$call->streamThumbnail();
161198
```
162199

163200
Get stream thumbnail `array`
201+
164202
```php
165203
$call->getStreamTags($streamid);
166204
```
167205

168206
Get top clips for game id `array`
207+
169208
```php
170209
$call->getGameClips($gameid);
171210
```
172211

173212
Get users top clips `array`
213+
174214
```php
175215
$call->getUserClips($user);
176216
```
177217

178218
Get users videos (most recent first) `array`
219+
179220
```php
180221
$call->getUserVideos($user);
181222
```
182223

183224
Get users videos for game id `array`
225+
184226
```php
185227
$call->getUserVideosForGame($user, $game_id);
186228
```
187229

188230
Get game data for game id `array`
231+
189232
```php
190233
$call->getGameData($game_id);
191234
```
192235

193236
Get game name `string`
237+
194238
```php
195239
$call->getGameData($game_id);
196240
$game_name = $call->gameName();
197241
```
198242

199243
Get game artwork `string`
244+
200245
```php
201246
$call->getGameData($game_id);
202247
$game_name = $call->gameArtwork();
203248
```
204249

205250
Get game artwork `string`
251+
206252
```php
207253
$call->getGameData($game_id);
208254
$game_name = $call->gameArtwork();
209255
```
210256

211-
Set JSON header
212-
```php
213-
$call->setJsonHeader();
214-
```
215-
216257
Custom array access `string`
258+
217259
```php
218260
//array return call here Eg:$call->getUserDetails('shroud');
219261
$custom = $call->getCustom(0, 'type');
220-
```
221-
222-
223-
## TODO
224-
225-
* Access to all values, not just popular ones.
226-
* Greater options to calls, add filter types (Newest, view count, length).
262+
```

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "corbpie/twitch-api-class",
3+
"description": "A PHP Twitch API wrapper",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"Corbpie\\TwitchApiClass\\": "src/"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "corbpie",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"minimum-stability": "dev",
18+
"require": {
19+
"php": ">=8.0",
20+
"ext-curl": "*"
21+
}
22+
}

composer.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2-
require_once('twitch-class.php');
3-
4-
$call = new twitch_call();
5-
$call->setApiKey('TWITCHCLIENTID');//Set client id
6-
$call->getUserStream('shroud');//Set streamers username
7-
if ($call->userIsLive()) {//Will return true is user is live/streaming
8-
echo "Shroud is streaming right now";
9-
}
2+
require_once('vendor/autoload.php');
3+
4+
use Corbpie\TwitchApiClass\twitchWrapper;
5+
6+
$call = new twitchWrapper();
7+
8+
echo $call->accessCodeUrl();
9+
10+
echo json_encode($call->getUserDetails('shroud'));

0 commit comments

Comments
 (0)