定制 zairakai/laravel-twitch 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zairakai/laravel-twitch

最新稳定版本:v2.0.8

Composer 安装命令:

composer require zairakai/laravel-twitch

包简介

Complete Twitch API integration package with OAuth, EventSub, badges system and event-driven architecture

README 文档

README

Main Develop Coverage

GitLab Release Packagist Downloads License

PHP Laravel Static Analysis Code Style

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 Twitch facade
  • OAuth 2.0 — authorization code flow, token refresh, and PKCE support via TwitchOAuth facade
  • 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:

KeyDescription
client_idTwitch application client ID
client_secretTwitch application client secret
redirect_uriOAuth callback URL
webhook_secretSecret for EventSub signature verification
cache_ttlTTL 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

License Security Policy Issues

Made with ❤️ by Zairakai

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固