play-code-live/vkplay-live-sdk

Access VKPlayLive API easily with PHP SDK

0.4.0 2024-05-04 01:36 UTC

This package is auto-updated.

Last update: 2024-05-04 01:40:04 UTC


README

Latest Version Maintainability Test Coverage

Installation

The recommended way to install VKPlayLiveSDK is through Composer.

composer require play-code-live/vkplay-live-sdk

Authorization

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);

Methods

Catalog

Channels Online

// 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);

Categories Online

// 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

$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 Search

$category = $client->searchCategory('Говорим и смотрим', limit: 20);
// or
$category = $client->searchCategory('Говорим и смотрим', limit: 20, accessToken: $tokenData->accessToken);

Channel

// 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;

Channels

// 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);

Channel Credentials

$credentials = $client->getChannelCredentials('play_code', $tokenData->accessToken);

// RTMP-stream url
$credentials->url;

// Stream token
$credentials->token;

License

VKPlayLiveSDK is made available under the MIT License (MIT). Please see License File for more information.