zairakai/laravel-twitch
Composer 安装命令:
composer require zairakai/laravel-twitch
包简介
Complete Twitch API integration package with OAuth, EventSub, badges system and event-driven architecture
README 文档
README
Complete Twitch API integration for Laravel: OAuth, Helix API, EventSub webhooks, and a badges system.
Features
- Helix API — games, streams, users, clips, channels, search, and more via
Twitchfacade - OAuth 2.0 — authorization code flow, token refresh, and PKCE support via
TwitchOAuthfacade - EventSub — subscribe to and handle Twitch webhook events with signature verification
- Badges system — fetch, cache, and display global and channel emote/badge sets
- Event-driven — Laravel events dispatched for every received EventSub notification
- Token management — automatic token refresh and storage
Install
composer require zairakai/laravel-twitch
Publish the config:
php artisan vendor:publish --tag=config
Add your credentials to .env:
TWITCH_CLIENT_ID=your_client_id
TWITCH_CLIENT_SECRET=your_client_secret
TWITCH_REDIRECT_URI=https://your-app.com/auth/twitch/callback
TWITCH_WEBHOOK_SECRET=your_webhook_secret
Usage
Helix API
use Zairakai\LaravelTwitch\Facades\Twitch;
// Get top games
$games = Twitch::getTopGames();
// Get streams by user ID(s)
$streams = Twitch::getStreams(userIds: ['12345', '67890']);
// Get users by login(s) or ID(s)
$users = Twitch::getUsers(logins: 'username');
// Get the currently authenticated user (after setAccessToken)
$me = Twitch::getAuthenticatedUser();
// Search channels
$results = Twitch::searchChannels('gaming');
OAuth
use Zairakai\LaravelTwitch\Facades\TwitchOAuth;
// Redirect to Twitch authorization
$authUrl = TwitchOAuth::getAuthorizationUrl(['user:read:email', 'channel:read:subscriptions']);
return redirect($authUrl);
// Exchange code for token (in callback controller)
$token = TwitchOAuth::getAccessToken(request('code'));
// Refresh token
$newToken = TwitchOAuth::refreshToken($refreshToken);
EventSub
// Subscribe to events (webhook transport)
Twitch::createEventSubSubscription(
type: 'stream.online',
condition: ['broadcaster_user_id' => $broadcasterId],
callbackUrl: route('twitch.webhook'),
secret: config('twitch.eventsub.webhook_secret'),
);
// Handle webhooks — in routes/web.php
Route::post('/twitch/webhook', [TwitchAuthController::class, 'webhook']);
// Listen to dispatched Laravel events (string-based)
Event::listen('twitch.stream.online', function (array $eventData) {
// handle the stream.online payload
});
Event::listen('twitch.channel.follow', function (array $eventData) {
// handle the channel.follow payload
});
Configuration
Key options in config/twitch.php:
| Key | Description |
|---|---|
client_id | Twitch application client ID |
client_secret | Twitch application client secret |
redirect_uri | OAuth callback URL |
webhook_secret | Secret for EventSub signature verification |
cache_ttl | TTL in seconds for API response caching |
Development
make quality # pint + phpstan + rector + insights + markdownlint + shellcheck
make quality-fast # pint + phpstan + markdownlint
make test # phpunit / pest
Getting Help
Made with ❤️ by Zairakai
zairakai/laravel-twitch 适用场景与选型建议
zairakai/laravel-twitch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「oauth」 「streaming」 「laravel」 「twitch」 「badges」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zairakai/laravel-twitch 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zairakai/laravel-twitch 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zairakai/laravel-twitch 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
WeChat OAuth SDK
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Library for ORCID web services
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
A PSR-7 compatible library for making CRUD API endpoints
A laravel bundle for the OpenTok PHP SDK
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 39
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-11