Skip to content

Commit c8ed550

Browse files
committed
Updated for OAuth & Cleaned up code
Updated for OAuth & Cleaned up code. Removed Doc comments and added return types
1 parent 8c7c6df commit c8ed550

File tree

2 files changed

+122
-273
lines changed

2 files changed

+122
-273
lines changed

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# Twitch API class
2+
3+
### Updated for OAuth usage!
4+
25
Feature packed, easy to use PHP class for the [latest](https://dev.twitch.tv/docs/api/) Twitch API.
36

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!
512

613
## Features
714

@@ -29,22 +36,36 @@ You will need your free Twitch Client Id to use, see [here](https://dev.twitch.t
2936

3037
## Usage
3138

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+
3245
Make sure the class file is included
3346
```php
3447
require_once('twitch-class.php');
3548
```
3649

37-
Then assign a new instance with your Twitch Client Id
50+
Then assign a new instance
3851
```php
3952
$call = new twitch_call();
40-
$call->setApiKey('TWITCHCLIENTID');//Set client id
4153
```
4254

4355
Get current top (view count) streams `array`
4456
```php
4557
$call->getTopStreams();
4658
```
4759

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+
4869
Get current top (view count) streams for a game `array`
4970
```php
5071
$call->getGameTopStreams($gameid);

0 commit comments

Comments
 (0)