vinlock / stream-api
PHP API Wrapper for Stream Services such as Twitch.tv and Hitbox.tv
1.4
2016-08-25 03:03 UTC
Requires
- php: >=7.0
- rmccue/requests: v1.6.1
This package is not auto-updated.
Last update: 2024-09-26 01:48:06 UTC
README
PHP API Wrapper for multiple streaming services.
注意: 更新即将到来,因为Twitch更新了其API,使当前版本已过时。
支持的服务提供商
通过Composer安装
$ composer require vinlock/stream-api
使用方法
合并游戏。
$twitch = \Vinlock\StreamAPI\Services\Twitch::game("Dota 2"); $hitbox = \Vinlock\StreamAPI\Services\Hitbox::game("Dota 2"); $merge = \Vinlock\StreamAPI\Services\Service::merge($twitch, $hitbox); echo $merge->getJSON(); // Displays all streams from highest to lowest viewers for Dota 2 on Twitch and Hitbox.
合并您想要的任意数量的游戏...
$bladeandsoul_twitch = \Vinlock\StreamAPI\Services\Twitch::game("Blade and Soul"); $bladeandsoul_hitbox = \Vinlock\StreamAPI\Services\Hitbox::game("Blade and Soul"); $overwatch_twitch = \Vinlock\StreamAPI\Services\Twitch::game("Overwatch"); $overwatch_hitbox = \Vinlock\StreamAPI\Services\Hitbox::game("Overwatch"); $merge = \Vinlock\StreamAPI\Services\Service::merge( $bladeandsoul_twitch, $bladeandsoul_hitbox, $overwatch_twitch, $overwatch_hitbox );
或者,您也可以将游戏作为数组传入。
$games = [ "Blade and Soul", "Overwatch", "Aion Online" ]; $twitch = \Vinlock\StreamAPI\Services\Twitch::game($games); $hitbox = \Vinlock\StreamAPI\Services\Hitbox::game($games); $merge = \Vinlock\StreamAPI\Services\Service::merge($twitch, $hitbox); // or pass the Service Objects as an array to be merged. $merge = \Vinlock\StreamAPI\Services\Service::merge( [ $twitch, $hitbox ] ); echo $merge->getJSON();
从用户名获取
结果将仅显示在线用户。
$twitch = new \Vinlock\StreamAPI\Services\Twitch("vinlockz"); $hitbox = new \Vinlock\StreamAPI\Services\Hitbox("vinlock");
或者传入多个用户名作为数组。
$twitch_streams = [ "trick2g", "vinlockz", ... ]; $hitbox_streams = [ "hitboxstream1", "hitboxstream2", ... ]; $twitch = new \Vinlock\StreamAPI\Services\Twitch($twitch_streams); $hitbox = new \Vinlock\StreamAPI\Services\Twitch($hitbox_streams);
然后也可以合并这些。
$merge = \Vinlock\StreamAPI\Services\Service::merge($twitch, $hitbox); // or $merge = \Vinlock\StreamAPI\Services\Service::merge( [ $twitch, $hitbox ] ); echo $merge->getJSON(); // Displays the information for all streams merged as JSON.
通用合并
您可以将通过用户名初始化的实例与通过游戏初始化的实例合并。
$bladeandsoul_twitch = \Vinlock\StreamAPI\Services\Twitch::game("Blade and Soul"); $twitch = new \Vinlock\StreamAPI\Services\Twitch("vinlockz"); $merge = \Vinlock\StreamAPI\Services\Service::merge($twitch, $bladeandsoul_twitch); $merge->getJSON();
数据检索
您可以从服务对象中获取数组、JSON或对象。
echo $merge->getJSON(); // Displays the information for all streams merged as JSON. echo $merge->getArray(); // Array echo $merge->getObject(); // Object
示例JSON
这将适用于每个流提供商。
[ { "username": "trick2g", "display_name": "Trick2g", "game": "League of Legends", "preview": { "small": "https://static-cdn.jtvnw.net/previews-ttv/live_user_trick2g-80x45.jpg", "medium": "https://static-cdn.jtvnw.net/previews-ttv/live_user_trick2g-320x180.jpg", "large": "https://static-cdn.jtvnw.net/previews-ttv/live_user_trick2g-640x360.jpg" }, "status": "100% Advan | Silver Clown Fiesta 101 How to TDM #Na Throws @Trick2g Day 35 No Sodabull", "bio": "Opening the Gates", "url": "https://www.twitch.tv/trick2g", "viewers": 4040, "id": 28036688, "avatar": "https://static-cdn.jtvnw.net/jtv_user_pictures/trick2g-profile_image-291046f75304f006-300x300.jpeg", "service": "twitch", "followers": 996140, "created_at": "05-31-2016 01:15:12", "updated_at": "05-31-2016 03:36:19" } ]