@@ -33,31 +33,52 @@ This class will automatically refresh access token once it expires!
33
33
* Get users clips
34
34
* Get game name for game id
35
35
* Get game artwork for game id
36
+ * PHP 8
36
37
37
38
## Usage
38
39
39
- Add your Twitch client id, client secret and authorization code into the constants (lines 5-7)
40
+ ** Fetch with composer: **
40
41
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
+ ```
42
45
43
- Change the token filename constant, however keep it as a .txt extension (line 9)
46
+ To use:
44
47
45
- Make sure the class file is included
46
48
``` php
47
- require_once('twitch-class.php');
49
+ require_once('vendor/autoload.php');
50
+
51
+ use Corbpie\TwitchApiClass\twitchWrapper;
52
+
53
+ $call = new twitchWrapper();
48
54
```
49
55
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
+
51
64
``` php
52
- $call = new twitch_call ();
65
+ echo $call->accessCodeUrl ();
53
66
```
54
67
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
+
55
74
Get current top (view count) streams ` array `
75
+
56
76
``` php
57
77
$call->getTopStreams();
58
78
```
59
79
60
80
<b >Protect your calls against an expired access token:</b >
81
+
61
82
``` php
62
83
$data = $call->getUserLiveData('summit1g');
63
84
if (!$call->checkCallSuccess($data)) {//Call failed but refreshed token, try it again:
@@ -67,17 +88,20 @@ echo $data;
67
88
```
68
89
69
90
Get current top (view count) streams for a game ` array `
91
+
70
92
``` php
71
93
$call->getGameTopStreams($gameid);
72
94
```
73
95
74
96
Get top (view count) streamer for a game ` string `
97
+
75
98
``` php
76
99
$call->getGameTopStreams($gameid);
77
100
echo $call->getTopStreamerForGame();
78
101
```
79
102
80
103
Get viewer count for the top stream for a game ` string `
104
+
81
105
``` php
82
106
$call->getGameTopStreams($gameid);
83
107
echo $call->getTopViewersForGame();
@@ -86,141 +110,153 @@ echo $call->getTopViewersForGame();
86
110
Get top games ` array `
87
111
88
112
(Good way to get gameid's)
113
+
89
114
``` php
90
115
$call->getTopGames();
91
116
```
92
117
93
118
Get details for username ` array `
119
+
94
120
``` php
95
121
$call->getUserDetails($username);
96
122
```
97
123
98
124
Get user id for username ` string `
125
+
99
126
``` php
100
127
$call->getUserDetails($username);
101
128
$user_id = $call->idForUser();
102
129
```
103
130
104
131
Get emotes for username ` array `
132
+
105
133
``` php
106
134
$call->getUserEmotes($username);
107
135
```
108
136
109
137
Get image for emote id ` string `
138
+
110
139
``` php
111
140
$call->emoteImage($emoteid);
112
141
```
113
142
114
-
115
143
Get chat for VOD ` array `
144
+
116
145
``` php
117
146
$call->chatForVod($vod_id, $offset);
118
147
```
119
148
120
-
121
149
Get users stream details (If live) ` array `
150
+
122
151
``` php
123
152
$call->getUserStream($username);
124
153
```
125
154
126
155
Check if a user is live and streaming ` boolean `
156
+
127
157
``` php
128
158
$call->getUserStream($username);
129
159
$call->userIsLive();//true for live | false for not live
130
160
```
161
+
131
162
__ If user is streaming:__
132
163
133
164
Get game id ` string `
165
+
134
166
``` php
135
167
$call->streamGameId();
136
168
```
137
169
138
170
Get viewer count ` string `
171
+
139
172
``` php
140
173
$call->streamViewers();
141
174
```
142
175
143
176
Get stream title ` string `
177
+
144
178
``` php
145
179
$call->streamTitle();
146
180
```
147
181
148
182
Get stream id ` string `
183
+
149
184
``` php
150
185
$call->streamId();
151
186
```
152
187
153
188
Get stream start time ` string `
189
+
154
190
``` php
155
191
$call->streamStart();
156
192
```
157
193
158
194
Get stream thumbnail ` string `
195
+
159
196
``` php
160
197
$call->streamThumbnail();
161
198
```
162
199
163
200
Get stream thumbnail ` array `
201
+
164
202
``` php
165
203
$call->getStreamTags($streamid);
166
204
```
167
205
168
206
Get top clips for game id ` array `
207
+
169
208
``` php
170
209
$call->getGameClips($gameid);
171
210
```
172
211
173
212
Get users top clips ` array `
213
+
174
214
``` php
175
215
$call->getUserClips($user);
176
216
```
177
217
178
218
Get users videos (most recent first) ` array `
219
+
179
220
``` php
180
221
$call->getUserVideos($user);
181
222
```
182
223
183
224
Get users videos for game id ` array `
225
+
184
226
``` php
185
227
$call->getUserVideosForGame($user, $game_id);
186
228
```
187
229
188
230
Get game data for game id ` array `
231
+
189
232
``` php
190
233
$call->getGameData($game_id);
191
234
```
192
235
193
236
Get game name ` string `
237
+
194
238
``` php
195
239
$call->getGameData($game_id);
196
240
$game_name = $call->gameName();
197
241
```
198
242
199
243
Get game artwork ` string `
244
+
200
245
``` php
201
246
$call->getGameData($game_id);
202
247
$game_name = $call->gameArtwork();
203
248
```
204
249
205
250
Get game artwork ` string `
251
+
206
252
``` php
207
253
$call->getGameData($game_id);
208
254
$game_name = $call->gameArtwork();
209
255
```
210
256
211
- Set JSON header
212
- ``` php
213
- $call->setJsonHeader();
214
- ```
215
-
216
257
Custom array access ` string `
258
+
217
259
``` php
218
260
//array return call here Eg:$call->getUserDetails('shroud');
219
261
$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
+ ```
0 commit comments