PHPackages                             raideer/twitch-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. raideer/twitch-api

AbandonedArchivedLibrary[API Development](/categories/api)

raideer/twitch-api
==================

Twitch.Tv API Wrapper in php

1.1(10y ago)32481MITPHP

Since Jan 26Pushed 10y ago2 watchersCompare

[ Source](https://github.com/raideer/twitch-api)[ Packagist](https://packagist.org/packages/raideer/twitch-api)[ RSS](/packages/raideer-twitch-api/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (4)Versions (5)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/59af341f39f4381dd985f513a4e80c952774254b37c4b29f2916272302bd64f5/68747470733a2f2f706f7365722e707567782e6f72672f726169646565722f7477697463682d6170692f762f737461626c65)](https://packagist.org/packages/raideer/twitch-api) [![Total Downloads](https://camo.githubusercontent.com/eedb5de11f179be3515163de610e1f40a6f63359d2d5047461ef99398d7a4ffb/68747470733a2f2f706f7365722e707567782e6f72672f726169646565722f7477697463682d6170692f646f776e6c6f616473)](https://packagist.org/packages/raideer/twitch-api) [![Latest Unstable Version](https://camo.githubusercontent.com/dd745c88ae1821401636f8ee1d6f658a543035b1f6c26f273b9a500215b68f5e/68747470733a2f2f706f7365722e707567782e6f72672f726169646565722f7477697463682d6170692f762f756e737461626c65)](https://packagist.org/packages/raideer/twitch-api) [![License](https://camo.githubusercontent.com/d6061ce888ef4bf82a5922b646d88ad09e838cc5c0098e9775a96a2fe8b015df/68747470733a2f2f706f7365722e707567782e6f72672f726169646565722f7477697463682d6170692f6c6963656e7365)](https://packagist.org/packages/raideer/twitch-api) [![StyleCI](https://camo.githubusercontent.com/be945216fe9dcaae9e9059ee6b0c8864917ade0ac9e3c3354840979a62ecde82/68747470733a2f2f7374796c6563692e696f2f7265706f732f34383538363735352f736869656c64)](https://styleci.io/repos/48586755)

Twitch API wrapper in PHP
=========================

[](#twitch-api-wrapper-in-php)

1. Installation
2. [Basic usage](#basic-unauthenticated-requests)
3. [Authenticated requests](#authenticated-requests)
4. [Resources](https://github.com/raideer/twitch-api/blob/master/resources.md)

Installation
------------

[](#installation)

`composer require raideer/twitch-api`

Usage
-----

[](#usage)

### Basic, unauthenticated requests.

[](#basic-unauthenticated-requests)

First we need to create the main Wrapper instance. The constructor takes a Guzzle Client as its only parameter.

```
$client = new GuzzleHttp\Client;

$wrapper = new Raideer\TwitchApi\Wrapper($client);
```

Now we can access various Twitch API resources using the wrapper.
You can see all the resources and their methods here:

```
/*
 * Wrapper->resource->function()
 */

$response = $wrapper->Channels->getChannel('lirik');
//OR
$response = $wrapper->resource('channels')->getChannel('lirik');
```

Note: letter capitalization desn't matter, so `$wrapper->CHANNELS->getChannel()` will still work.

Some methods can take an optional array of parameters.
See the [official twitch api](https://github.com/justintv/Twitch-API) documentation for the list of parameters.

```
$wrapper->Channels->getFollows('lirik', ['limit' => 40, 'direction' => 'asc']);
```

### Authenticated requests

[](#authenticated-requests)

First we need to create an OAuth object, that will contain the necessary information for authenticating our requests.

Read more about [authentication here](https://github.com/justintv/Twitch-API/blob/master/authentication.md).

```
$settings = [
  'client_id'     => 'Your Client ID',
  'client_secret' => 'Your Client Secret',
  'redirect_uri'  => 'Your registered redirect URI',
  'state'         => 'Your provided unique token',
  'scope'         => 'Array or space seperated string of scopes'
];

$oauth = new Raideer\TwitchApi\OAuth($settings);

//Returns the authentication URL
$url = $oauth->getUrl();
```

Once the user authorizes your application, they will be redirected to your specified URI with a code, that's necessary for obtaining the access token.

##### Obtaining the Access Token

[](#obtaining-the-access-token)

You can obtain the access token by using the getResponse method. If the request is successful, *OAuthResponse* object will be returned. It contains the access token, refresh token and registered scopes.

```
$response = $oauth->getResponse($code);

$response->getAccessToken();
$response->getRefreshToken(); //Token refreshing isn't implemented yet
$response->getScope();
$response->hasScope($scope);
```

Now you can authorize the Wrapper using the *authorize* method.

```
//You can pass the OAuthResponse object directly
$wrapper->authorize($response);

//Or just pass the access token
$wrapper->authorize($accessToken);

//Or pass both access token and registered scopes array
$wrapper->authorize($accessToken, $registeredScopes);
```

If you authorize the wrapper only by passing the access token, the Wrapper will not be able to check whether the scope you're trying to access actually exists. (Useful if you don't want to make unnecessary requests)

Now you can make authorized requests.

```
$wrapper->Channels->getChannel(); //Returns the authenticated user's channel
```

If the request is out of scope, `Raideer\TwitchApi\Exceptions\OutOfScopeException` will be thrown.

##### Throttling (under construction)

[](#throttling-under-construction)

If you need, you can enable request throttling.

```
$wrapper->enableThrottle(true);
```

Time (milliseconds) between requests can be set like so:

```
// 1 second throttle
$wrapper->setThrottleInterval(1000);
```

#### Examples

[](#examples)

```
$client = new GuzzleHttp\Client;
$wrapper = new Raideer\TwitchApi\Wrapper($client);

$settings = [
  'client_id'     => 'myClientId',
  'client_secret' => 'myClientSecret',
  'redirect_uri'  => 'http://localhost',
  'state'         => 'myUniqueToken123123',
  'scope'         => ['channel_editor']
];

$oauth = new Raideer\TwitchApi\OAuth($settings);

// You can also add a scope using the addScope method
$oauth->addScope('channel_read');

$url = $oauth->getUrl();
```

```
$code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_STRING);
$response = $oauth->getResponse($code);
$wrapper->authorize($response);

$channel = $wrapper->Channels->getChannel();

echo "I'm currently playing " . $channel->game;
```

### [Resources and their methods](https://github.com/raideer/twitch-api/blob/master/resources.md)

[](#resources-and-their-methods)

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Total

4

Last Release

3779d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9fb995db1ad62773631adcef9d00da771443729646c55432c7b2e5f7b90c0bb9?d=identicon)[Kristofers Ozolins](/maintainers/Kristofers%20Ozolins)

---

Top Contributors

[![raideer](https://avatars.githubusercontent.com/u/8568120?v=4)](https://github.com/raideer "raideer (117 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/raideer-twitch-api/health.svg)

```
[![Health](https://phpackages.com/badges/raideer-twitch-api/health.svg)](https://phpackages.com/packages/raideer-twitch-api)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M723](/packages/sylius-sylius)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k36](/packages/neuron-core-neuron-ai)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M545](/packages/shopware-core)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k59](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
