PHPackages                             bulgarianhealer/laravel-twitch - 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. bulgarianhealer/laravel-twitch

ActiveLibrary[API Development](/categories/api)

bulgarianhealer/laravel-twitch
==============================

Twitch PHP Wrapper for Laravel

3.0.3(5y ago)09MITPHPPHP &gt;=7.2

Since Feb 6Pushed 5y agoCompare

[ Source](https://github.com/BulgarianHealer/Laravel-Twitch)[ Packagist](https://packagist.org/packages/bulgarianhealer/laravel-twitch)[ RSS](/packages/bulgarianhealer-laravel-twitch/feed)WikiDiscussions l8 Synced 2w ago

READMEChangelog (2)Dependencies (6)Versions (46)Used By (0)

Laravel Twitch
==============

[](#laravel-twitch)

[![Latest Stable Version](https://camo.githubusercontent.com/0089ec267b80ceb6422b6e4a80e9b44ddb1e73dede3f36b221658b252cf6a251/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f6d616e7a6970702f6c61726176656c2d7477697463682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/romanzipp/laravel-twitch)[![Total Downloads](https://camo.githubusercontent.com/074f90696adcdac36dcb7855ce13a803f3bdad611c142463688d947459a80fa1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f6d616e7a6970702f6c61726176656c2d7477697463682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/romanzipp/laravel-twitch)[![License](https://camo.githubusercontent.com/45d6ca2ec08ed47f72d06c22ffb7bb22eb817eb2560f1eb9cfe082b8d86f2229/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f726f6d616e7a6970702f6c61726176656c2d7477697463682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/romanzipp/laravel-twitch)[![Code Quality](https://camo.githubusercontent.com/6e9a6d358e06271e7e2897d89ba376a35f47b1585bb356acd3f294b5f45b1452/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f726f6d616e7a6970702f6c61726176656c2d7477697463682e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/romanzipp/laravel-twitch/?branch=master)[![GitHub Build Status](https://camo.githubusercontent.com/1a023b9f8b7e937333fdd3fe685dd9393dfd5290b2172a8308a81769fe7015b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f726f6d616e7a6970702f4c61726176656c2d5477697463682f54657374733f7374796c653d666c61742d737175617265)](https://github.com/romanzipp/Laravel-Twitch/actions)

PHP Twitch Helix API Wrapper for Laravel 5+

⚠️ Changes on May 01, 2020
--------------------------

[](#️-changes-on-may-01-2020)

Since May 01, 2020, Twitch requires all requests to contain a valid OAuth Access Token. This can be achieved by requesting an OAuth Token using the [Client Credentials Flow](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth#oauth-client-credentials-flow).

If you don't handle this by yourself, be sure to enable the built-in Access Token generation feature via the `oauth_client_credentials.auto_generate` configuration entry.

You will need define a valid **Client ID** and **Client Secret** via your config or the available setters! See the [full config](https://github.com/romanzipp/Laravel-Twitch/blob/master/config/twitch-api.php) for more details.

Table of contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Configuration](#configuration)
3. [Examples](#examples)
4. [Documentation](#documentation)
5. [Upgrading](#upgrading)
6. [Development](#Development)

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

[](#installation)

```
composer require romanzipp/laravel-twitch

```

**If you use Laravel 5.5+ you are already done, otherwise continue.**

Add Service Provider to your `app.php` configuration file:

```
romanzipp\Twitch\Providers\TwitchServiceProvider::class,
```

Configuration
-------------

[](#configuration)

Copy configuration to config folder:

```
$ php artisan vendor:publish --provider="romanzipp\Twitch\Providers\TwitchServiceProvider"

```

Add environmental variables to your `.env`

```
TWITCH_HELIX_KEY=
TWITCH_HELIX_SECRET=
TWITCH_HELIX_REDIRECT_URI=http://localhost

```

Examples
--------

[](#examples)

### Basic

[](#basic)

```
$twitch = new romanzipp\Twitch\Twitch;

$twitch->setClientId('abc123');

// Get User by Username
$result = $twitch->getUsers(['login' => 'herrausragend']);

// Check, if the query was successful
if ( ! $result->success()) {
    return null;
}

// Shift result to get single user data
$user = $result->shift();

return $user->id;
```

### Setters

[](#setters)

```
$twitch = new romanzipp\Twitch\Twitch;

$twitch->setClientId('abc123');
$twitch->setClientSecret('abc456');
$twitch->setToken('abcdef123456');

$twitch = $twitch->withClientId('abc123');
$twitch = $twitch->withClientSecret('abc123');
$twitch = $twitch->withToken('abcdef123456');
```

### OAuth Tokens

[](#oauth-tokens)

```
$twitch = new romanzipp\Twitch\Twitch;

$twitch->setClientId('abc123');
$twitch->setToken('abcdef123456');

$result = $twitch->getUsers(['login' => 'herrausragend']);
```

### OAuth Client Credentials Flow

[](#oauth-client-credentials-flow)

Since May 01, 2020, every request requires an OAuth token which can be issued using the [OAuth Client Credentials Flow](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#oauth-client-credentials-flow).

```
use romanzipp\Twitch\Enums\GrantType;
use romanzipp\Twitch\Twitch;

$twitch = new Twitch;

$twitch->setClientId('abc123');
$twitch->setClientSecret('def123');
$twitch->setToken('abcdef123456');

$result = $twitch->getOAuthToken(null, GrantType::CLIENT_CREDENTIALS, ['user:read']);

if ( ! $result->success()) {
    return;
}

$accessToken = $result->data()->access_token;
```

### Pagination

[](#pagination)

The Twitch API returns a `paginator` field with paginated results like `/streams`, `/follows`or `/games`. To jump between pages, the given cursor must be appended to the following query using the direction attributes `after` or `before`.

In this example, we will fetch a set of streams and use the provided cursor to switch to the next/previous set of data.

❗️ To prevent infinite loops or errors, use the `Result::hasMoreResults()` method to check if there are more results available.

```
$twitch = new romanzipp\Twitch\Twitch;

// Page 1
$firstResult = $twitch->getStreams(['language' => 'de']);

// Page 2
$secondResult = $twitch->getStreams(['language' => 'de'], $firstResult->next());

// Page 1 (again)
$thirdResult = $twitch->getStreams(['language' => 'de'], $secondResult->back());
```

### Facade

[](#facade)

```
use romanzipp\Twitch\Facades\Twitch;

Twitch::withClientId('abc123')->withToken('abcdef123456')->getUsers();
```

### Pagination Loop Example

[](#pagination-loop-example)

This example fetches all Twitch Games and stores them into a database.

```
use romanzipp\Twitch\Twitch;

$twitch = new Twitch;

do {
    $nextCursor = null;

    // If this is not the first iteration, get the page cursor to the next set of results
    if (isset($result)) {
        $nextCursor = $result->next();
    }

    // Query the API with an optional cursor to the next results page
    $result = $twitch->getTopGames(['first' => 100], $nextCursor);

    foreach ($result->data as $item) {
        // Process the games result data
    }

    // Continue until there are no results left
} while ($result->hasMoreResults());
```

### Insert user objects

[](#insert-user-objects)

The new API does not include the user objects in endpoints like followers or bits.

```
[
  {
    "from_id": "123456",
    "to_id": "654321",
    "followed_at": "2018-01-01 12:00:00"
  }
]
```

You can just call the [insertUsers](https://github.com/romanzipp/Laravel-Twitch/blob/master/src/Result.php#L233) method to insert all user data identified by `from_id` into `from_user`

```
use romanzipp\Twitch\Twitch;

$twitch = new Twitch;

$result = $twitch->getUsersFollows(['to_id' => 654321]);

$result->insertUsers('from_id', 'from_user');
```

**New Result data:**

```
[
  {
    "from_id": "123456",
    "to_id": "654321",
    "followed_at": "2018-01-01 12:00:00",
    "from_user": {
      "id": "123456",
      "display_name": "HerrAusragend",
      "login": "herrausragend"
    }
  }
]
```

Documentation
-------------

[](#documentation)

**Twitch Helix API Documentation: **

### OAuth

[](#oauth)

```
public function getOAuthAuthorizeUrl(string $responseType = 'code', array $scopes = [], ?string $state = NULL, bool $forceVerify = false)
public function getOAuthToken(?string $code = NULL, string $grantType = 'authorization_code', array $scopes = [])
```

### Ads

[](#ads)

```
public function startCommercial(array $parameters = [])
```

### Analytics

[](#analytics)

```
public function getExtensionAnalytics(array $parameters = [])
public function getGameAnalytics(array $parameters = [])
```

### Bits

[](#bits)

```
public function getCheermotes(array $parameters = [])
public function getBitsLeaderboard(array $parameters = [])
public function getExtensionTransactions(array $parameters = [])
```

### Clips

[](#clips)

```
public function createClip(array $parameters = [])
public function getClips(array $parameters = [])
```

### Entitlements

[](#entitlements)

```
public function createEntitlementUrl(array $parameters = [])
public function getEntitlementsCodeStatus(array $parameters = [])
public function getDropsEntitlements(array $parameters = [])
public function redeemEntitlementsCode(array $parameters = [])
```

### Extensions

[](#extensions)

```
public function getAuthedUserExtensions()
public function getAuthedUserActiveExtensions()
public function disableAllExtensions()
public function disableUserExtensionById(?string $parameter = NULL)
public function disableUserExtensionByName(?string $parameter = NULL)
public function updateUserExtensions(?string $method = NULL, ?string $parameter = NULL, bool $disabled = false)
```

### Games

[](#games)

```
public function getTopGames(array $parameters = [], ?Paginator $paginator = NULL)
public function getGames(array $parameters = [])
```

### HypeTrain

[](#hypetrain)

```
public function getHypeTrainEvents(array $parameters = [])
```

### Search

[](#search)

```
public function searchCategories(array $parameters = [])
public function searchChannels(array $parameters = [])
```

### Streams

[](#streams)

```
public function getStreamKey(array $parameters = [])
public function getStreams(array $parameters = [], ?Paginator $paginator = NULL)
public function createStreamMarker(array $parameters = [], array $body = [])
public function getStreamMarkers(array $parameters = [], ?Paginator $paginator = NULL)
public function getChannels(array $parameters = [])
public function updateChannels(array $parameters = [], array $body = [])
```

### Users

[](#users)

```
public function createUserFollows(array $parameters = [], array $body = [])
public function deleteUserFollows(array $parameters = [])
public function getUsers(array $parameters = [])
public function getUsersFollows(array $parameters = [], ?Paginator $paginator = NULL)
public function updateUser(array $parameters = [])
public function getUserExtensions(array $parameters = [])
public function getUserActiveExtensions(array $parameters = [])
public function updateUserExtension(array $parameters = [], array $body = [])
```

### Videos

[](#videos)

```
public function getVideos(array $parameters = [], ?Paginator $paginator = NULL)
```

### Subscriptions

[](#subscriptions)

```
public function getSubscriptions(array $parameters = [], ?Paginator $paginator = NULL)
```

### Tags

[](#tags)

```
public function getStreamTags(array $parameters = [])
public function getAllStreamTags(array $parameters = [], ?Paginator $paginator = NULL)
public function replaceStreamTags(array $parameters = [], array $body = [])
```

### Moderation

[](#moderation)

```
public function checkAutoModStatus(array $parameters = [], array $body = [])
public function getBannedUsers(array $parameters = [], ?Paginator $paginator = NULL)
public function getBannedEvents(array $parameters = [], ?Paginator $paginator = NULL)
public function getModerators(array $parameters = [], ?Paginator $paginator = NULL)
public function getModeratorEvents(array $parameters = [], ?Paginator $paginator = NULL)
```

### Webhooks

[](#webhooks)

```
public function getWebhookSubscriptions(array $parameters = [])
public function subscribeWebhook(array $parameters = [], array $body = [])
public function unsubscribeWebhook(array $parameters = [], array $body = [])
public function buildWebhookTopic(string $path, array $parameters = [])
```

[**OAuth Scopes Enums**](https://github.com/romanzipp/Laravel-Twitch/blob/master/src/Enums/Scope.php)

Upgrading
---------

[](#upgrading)

- [**Upgrade from 2.0 to 3.0**](https://github.com/romanzipp/Laravel-Twitch/releases/tag/3.0.0)
- [Upgrade from 1.0 to 2.0](https://github.com/romanzipp/Laravel-Twitch/releases/tag/2.0.0)

Development
-----------

[](#development)

#### Run Tests

[](#run-tests)

```
composer test
```

```
CLIENT_ID=xxxx composer test
```

```
CLIENT_ID=xxxx CLIENT_SECRET=xxxx composer test
```

#### Generate Documentation

[](#generate-documentation)

```
composer docs
```

---

Join the Twitch Dev Discord!

[![Discord](https://camo.githubusercontent.com/6e3863c9a81ce03ad5ab796f034c4b537ef701c0b58ba1651b187150f16f8f70/68747470733a2f2f646973636f72646170702e636f6d2f6170692f6775696c64732f3530343031353535393235323337373630312f656d6265642e706e673f7374796c653d62616e6e657232)](https://discord.gg/YAMGgZT)

[![Discord](https://camo.githubusercontent.com/35d81c0ac73a1858bc16f5cd34de3b088e577f5126c47b5a982debe3e389ece3/68747470733a2f2f646973636f72646170702e636f6d2f6170692f6775696c64732f3332353535323738333738373033323537362f656d6265642e706e673f7374796c653d62616e6e657232)](https://discord.gg/8NXaEyV)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 96.6% 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 ~22 days

Total

44

Last Release

2155d ago

Major Versions

1.0.22 → 2.0.02019-05-28

2.3.3 → 3.0.02020-09-03

PHP version history (2 changes)1.0.0PHP &gt;=7.0

2.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/92ea75671991229b68263158e4b9fcc0527be358e097ec2a86e5b68b50c73808?d=identicon)[Krokit](/maintainers/Krokit)

---

Top Contributors

[![romanzipp](https://avatars.githubusercontent.com/u/11266773?v=4)](https://github.com/romanzipp "romanzipp (288 commits)")[![ghostzero](https://avatars.githubusercontent.com/u/6547306?v=4)](https://github.com/ghostzero "ghostzero (5 commits)")[![TylerFiekens](https://avatars.githubusercontent.com/u/30887168?v=4)](https://github.com/TylerFiekens "TylerFiekens (3 commits)")[![BulgarianHealer](https://avatars.githubusercontent.com/u/8360887?v=4)](https://github.com/BulgarianHealer "BulgarianHealer (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bulgarianhealer-laravel-twitch/health.svg)

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

###  Alternatives

[propaganistas/laravel-disposable-email

Disposable email validator

6023.2M7](/packages/propaganistas-laravel-disposable-email)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k161.4k2](/packages/mike-bronner-laravel-model-caching)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

265.2k](/packages/aedart-athenaeum)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9922.4M146](/packages/roots-acorn)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[spatie/laravel-export

Create a static site bundle from a Laravel app

679153.2k7](/packages/spatie-laravel-export)

PHPackages © 2026

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