play-code-live / vkplay-live-sdk
使用 PHP SDK 轻松访问 VKPlayLive API
0.4.0
2024-05-04 01:36 UTC
Requires
- php: >=8.1.2
- guzzlehttp/guzzle: ^7.8
Requires (Dev)
- phpunit/phpunit: ^10.5
README
安装
推荐安装 VKPlayLiveSDK 的方式是通过 Composer。
composer require play-code-live/vkplay-live-sdk
授权
use PlayCode\VKPlayLiveSDK\Client; use PlayCode\VKPlayLiveSDK\Scope; use PlayCode\VKPlayLiveSDK\Request\RevokeRequest; [ $clientId, $clientSecret, $redirectUri ] = ['...', '...', '...']; // Initialize the client $client = new Client($clientId, $clientSecret); // Get auth link $authLink = $client->getAuthLink($redirectUri, [ Scope::CHANNEL_POINTS, Scope::CHANNEL_ROLES, ]); // We'll get Code form the URL query parameter `?code` $code = '...'; // Get token data $tokenData = $client->getAccessToken($code, $redirectUri); print("Access token: " . $tokenData->accessToken); print("Refresh token: " . $tokenData->refreshToken); print("Expires in: " . $tokenData->expiresIn); // Refresh token $tokenData = $client->refreshToken($tokenData->refreshToken); // Revoke token $client->revokeToken($tokenData->accessToken); // or $client->revokeToken($tokenData->refreshToken, RevokeRequest::HINT_REFRESH_TOKEN);
方法
目录
在线频道
// Limit is required and cannot be more than 200 $client->listChannelsOnline(limit: 20); // You can specify category id $client->listChannelsOnline(20, categoryId: '4588a9f0-b606-4827-9b6a-f2da4309c196'); // Or category type $client->listChannelsOnline(20, categoryType: Category::TYPE_GAME); // It works with clientId and clientSecret, but you can use access_token $client->listChannelsOnline(20, accessToken: $tokenData->accessToken);
在线分类
// Limit is required and cannot be more than 200 $client->listCategoriesOnline(limit: 20); // You can specify category type $client->listCategoriesOnline(20, categoryType: Category::TYPE_GAME); // It works with clientId and clientSecret, but you can use access_token $client->listCategoriesOnline(20, accessToken: $tokenData->accessToken);
分类
$category = $client->getCategory('3c6b4b27-75f2-49c4-b967-f15aa88e2038'); // or $category = $client->getCategory('3c6b4b27-75f2-49c4-b967-f15aa88e2038', $tokenData->accessToken); // Title of the category $category->title; // Image url $category->coverUrl; // Type of category. @see Category::class $category->type;
分类搜索
$category = $client->searchCategory('Говорим и смотрим', limit: 20); // or $category = $client->searchCategory('Говорим и смотрим', limit: 20, accessToken: $tokenData->accessToken);
频道
// You can get channel data with clientId and clientSecret $channelInfo = $client->getChannel('play_code'); // Or with access_token $channelInfo = $client->getChannel('play_code', $tokenData->accessToken); // It contains all the data about channel. Example: $channelInfo->channelInfo->subscribers; // Followers count $channelInfo->channelInfo->status; // Current status // Socket addresses $channelInfo->channelInfo->webSocketChannels->chat; // Owner info $channelInfo->owner->avatarUrl; $channelInfo->owner->nick; $channelInfo->owner->isVerifiedStreamer; // Stream info $channelInfo->streamInfo->title; $channelInfo->streamInfo->category->title; $channelInfo->streamInfo->counters->viewers;
频道
// In the same way you can fetch up to 100 channels $channels = $client->getChannels([ 'play_code', 'vkplay', 'murmoshow', ]); // Or with access_token $channels = $client->getChannels([ 'play_code', 'vkplay', 'murmoshow', ], $tokenData->accessToken);
频道凭据
$credentials = $client->getChannelCredentials('play_code', $tokenData->accessToken); // RTMP-stream url $credentials->url; // Stream token $credentials->token;
许可证
VKPlayLiveSDK 在 MIT 许可证(MIT)下提供。请参阅 许可证文件 了解更多信息。