|
1 | 1 | # Twitch API class
|
| 2 | + |
| 3 | +### Updated for OAuth usage! |
| 4 | + |
2 | 5 | Feature packed, easy to use PHP class for the [latest](https://dev.twitch.tv/docs/api/) Twitch API.
|
3 | 6 |
|
4 |
| -You will need your free Twitch Client Id to use, see [here](https://dev.twitch.tv/docs/api/#step-1-setup) to obtain. |
| 7 | +You will need your free Twitch client id to use, see [here](https://dev.twitch.tv/docs/api/#step-1-setup) to obtain. |
| 8 | + |
| 9 | +To get your authorization code see [here](https://write.corbpie.com/twitch-api-authentication-with-oauth-using-php/). |
| 10 | + |
| 11 | +This class will automatically refresh access token once it expires! |
5 | 12 |
|
6 | 13 | ## Features
|
7 | 14 |
|
@@ -29,22 +36,36 @@ You will need your free Twitch Client Id to use, see [here](https://dev.twitch.t
|
29 | 36 |
|
30 | 37 | ## Usage
|
31 | 38 |
|
| 39 | +Add your Twitch client id, client secret and authorization code into the constants (lines 5-7) |
| 40 | + |
| 41 | +Add your redirect URI [info](https://write.corbpie.com/twitch-api-authentication-with-oauth-using-php/) (line 8) |
| 42 | + |
| 43 | +Change the token filename constant, however keep it as a .txt extension (line 9) |
| 44 | + |
32 | 45 | Make sure the class file is included
|
33 | 46 | ```php
|
34 | 47 | require_once('twitch-class.php');
|
35 | 48 | ```
|
36 | 49 |
|
37 |
| -Then assign a new instance with your Twitch Client Id |
| 50 | +Then assign a new instance |
38 | 51 | ```php
|
39 | 52 | $call = new twitch_call();
|
40 |
| -$call->setApiKey('TWITCHCLIENTID');//Set client id |
41 | 53 | ```
|
42 | 54 |
|
43 | 55 | Get current top (view count) streams `array`
|
44 | 56 | ```php
|
45 | 57 | $call->getTopStreams();
|
46 | 58 | ```
|
47 | 59 |
|
| 60 | +<b>Protect your calls against an expired access token:</b> |
| 61 | +```php |
| 62 | +$data = $call->getUserLiveData('summit1g'); |
| 63 | +if (!$call->checkCallSuccess($data)) {//Call failed but refreshed token, try it again: |
| 64 | + $data = $call->getUserLiveData('summit1g'); |
| 65 | +} |
| 66 | +echo $data; |
| 67 | +``` |
| 68 | + |
48 | 69 | Get current top (view count) streams for a game `array`
|
49 | 70 | ```php
|
50 | 71 | $call->getGameTopStreams($gameid);
|
|
0 commit comments