定制 simply-stream/twitch-api 二次开发

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

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

simply-stream/twitch-api

Composer 安装命令:

composer require simply-stream/twitch-api

包简介

README 文档

README

QA codecov

Welcome to the PHP Twitch Helix API Library, a powerful and developer-friendly implementation of the new Twitch API " Helix," complete with robust EventSub functionality. This library seamlessly integrates the latest features from Twitch, providing a straightforward and efficient way to interact with the Twitch platform in your PHP projects.

Key Features

Helix API Support: Harness the full potential of the Twitch Helix API with ease. Retrieve user information, access streams, and more, all through a clean and intuitive PHP interface.

EventSub Functionality: Embrace the future of Twitch event handling with our comprehensive EventSub implementation. Keep your application in sync with real-time events, ensuring timely and accurate updates.

Webhook Integration: Our library fully supports webhook communication for EventSub, enabling seamless communication between Twitch and your application. Stay informed about user activities and channel events effortlessly.

Data Transfer Objects (DTOs): Differentiating itself from traditional approaches, our library employs Data Transfer Objects (DTOs) to map incoming JSON responses to PHP objects. This abstraction simplifies the handling of Twitch data, enhancing code readability and maintainability.

To see a full list of implemented APIs, have a look at the Implemented APIs section.

Installation

composer req simplystream/twitch-api

Implemented APIs

API Implemented Tested
AdsApi ℹ️
AnalyticsApi
BitsApi ℹ️
ChannelPointsApi
ChannelsApi
CharityApi
ChatApi
ClipsApi
ContentClassificationApi
EntitlementsApi
EventSubApi
EventSub system
ExtensionsApi
GamesApi
GoalsApi
GuestStarApi (Beta)
HypeTrainApi
ModerationApi ℹ️
PollsApi
PredictionsApi
RaidsApi
ScheduleApi
SearchApi
StreamsApi
SubscriptionsApi
TeamsApi
UsersApi ℹ️
VideosApi
WhispersApi

❗ = Tests can't be implemented due to lack of mock-api-data. Mapping should work on Twitch prod systems ️️ℹ️ = Some tests are available, some are missing due to lack of mock-api data. Mapping should work on Twitch prod systems

Tested in this case means, that functional or unit tests exist.

There's also a container api service that can hold all the APIs implemented. See TwitchApi.

EventSub

Besides the APIs, there's also a service available for the EventSub handling. This service will handle the registration to an event and also the webhook callbacks by validating the challenge send by Twitch.

Please note, that this package only supports the webhook implementation! This is due to the fact, that PHP might not be the ideal programming language to use for long running processes like a websocket.

Websocket

To use the websocket implementation, you should check out the following projects:

Usage

To get everything up and running, you need to set some things up.

$client = new Client();
// Same for the request factory, it just needs to implement the RequestFactoryInterface&StreamFactoryInterface.
// Optionally the UriFactoryInterface, too, if you want to use the same object for the UriFactory.
$requestFactory = new RequestFactory();

$apiClient = new ApiClient(
    $client,
    $requestFactory,
    new \CuyZ\Valinor\MapperBuilder(),
    $requestFactory,
    ['clientId' => 'YOUR_CLIENT_ID', 'webhook' => ['secret' => 'YOUR_SECRET']]
);

$usersApi = new UsersApi($apiClient)
$response = $usersApi->getUsers(logins: ['some_login_name'], accessToken: $accessToken);

foreach($response->getData() as $user) {
    echo $user->getDisplayName();
}

Bring your own client

Instead of forcing you to implement yet another HTTP client, this library gives you the opportunity to use your own. The only restriction you got: It has to be PSR-18 compliant and implement the interface \Psr\Http\Client\ClientInterface.

We recommend either using the all in one package Guzzlehttp or PHP-HTTP with the PSR7 implementation Nyholm/PSR7 or Guzzle/PSR7.

AccessToken

In older versions, the AccessToken have been autogenerated by the sendRequest method by a TwitchProvider that has been build into this library. This provider is now removed and you need to give the $api->sendRequest(...) method an AccessToken yourself!

Due to the fact that this library still requires the PHP league implementation of an AccessTokenInterface, we recommend using https://github.com/vertisan/oauth2-twitch-helix to generate an AccessToken.

Supported Frameworks

Currently, there is only an integration for Symfony.

TODO List

Even though most of this library is ready to use, there's still a lot to do. Here is a brief overview of what will come next ordered more or less by priority:

  • Factories/Builder to easily instantiate the APIs and maybe some DTOs, especially the TwitchApi class
  • Middleware features, to easily extend requests (e.g.: RateLimitMiddleware)
  • A guideline for contributions

Contribution

We welcome contributions! Feel free to open issues, submit pull requests, or join our community discussions. A short guide for contribution will follow.

Support

You really like this project and want to support us in a different way than contribution? Feel free to support me on Ko-fi ♥️

ko-fi

simply-stream/twitch-api 适用场景与选型建议

simply-stream/twitch-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 455 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 simply-stream/twitch-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 simply-stream/twitch-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 simply-stream/twitch-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-19