PHP code example of play-code-live / vkplay-live-sdk

1. Go to this page and download the library: Download play-code-live/vkplay-live-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

play-code-live / vkplay-live-sdk example snippets



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 stChannelsOnline(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 stCategoriesOnline(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;