1. Go to this page and download the library: Download api-video/php-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/ */
api-video / php-sdk example snippets
thenticate in production environment
$client = ApiVideo\Client\Client::create('yourProductionApiKey');
// Alternatively, authenticate in sandbox environment for testing
$client = ApiVideo\Client\Client::createSandbox('yourSandboxApiKey');
// Create and upload a video resource from local drive
$video = $client->videos->upload(
'/path/to/video.mp4',
array('title' => 'Course #4 - Part B')
);
// Display embed code
echo $video->assets['iframe'];
// <iframe src="https://embed.api.video/vod/viXXX" width="100%" height="100%" frameborder="0" scrolling="no" allowfullscreen=""></iframe>
// Create and upload a video resource from online source (third party)
$video = $client->videos->download(
'https://www.example.com/path/to/video.mp4',
'Course #4 - Part B'
);
// Update video properties
$client->videos->update(
$video->videoId,
array(
'tags' => array('course', 'economics', 'finance')
)
);
// Search video by tags filter and paginate results
$videos = $client->videos->search(
array(
'currentPage' => 1,
'pageSize' => 25,
'tags' => array('finance')
)
);
foreach ($videos as $video) {
echo $video->title."\n";
}
// Delete video resource
$client->videos->delete($video->videoId);
// Upload a video thumbnail
$client->videos->uploadThumbnail('/path/to/thumbnail.jpg', $video->videoId);
// Update video thumbnail by picking image with video timecode
$client->videos->updateThumbnailWithTimeCode($video->videoId, '00:15:22.05');
// Create players with default values
$player = $client->players->create();
// Get a player
$player = $client->players->get($player->playerId);
// Search a player with paginate results
$players = $client->players->search(array('currentPage' => 1, 'pageSize' => 50));
$properties = array(
'shapeMargin' => 10,
'shapeRadius' => 3,
'shapeAspect' => 'flat',
'shapeBackgroundTop' => 'rgba(50, 50, 50, .7)',
'shapeBackgroundBottom' => 'rgba(50, 50, 50, .8)',
'text' => 'rgba(255, 255, 255, .95)',
'link' => 'rgba(255, 0, 0, .95)',
'linkHover' => 'rgba(255, 255, 255, .75)',
'linkActive' => 'rgba(255, 0, 0, .75)',
'trackPlayed' => 'rgba(255, 255, 255, .95)',
'trackUnplayed' => 'rgba(255, 255, 255, .1)',
'trackBackground' => 'rgba(0, 0, 0, 0)',
'backgroundTop' => 'rgba(72, 4, 45, 1)',
'backgroundBottom' => 'rgba(94, 95, 89, 1)',
'backgroundText' => 'rgba(255, 255, 255, .95)',
'enableApi' => false,
'enableControls' => true,
'forceAutoplay' => false,
'hideTitle' => false,
'forceLoop' => false
);
// Update player properties
$client->players->update($player->playerId, $properties);
// Upload player logo
$client->players->uploadLogo('/path/to/logo.png', $playerId, 'https://api.video');
// Delete a player
$client->players->delete($player->playerId);
// Upload video caption
$client->captions->upload(
'path/to/caption.vtt',
array(
'videoId' => $video->videoId,
'language' => 'en'
)
);
// Get video caption by language
$caption = $client->captions->get($video->videoId, 'en');
// Update the default caption language
$client->captions->updateDefault($video->videoId, 'en', true);
//Delete caption by language
$client->captions->delete($video->videoId, 'en');
// Upload video chapter
$client->chapters->upload(
'path/to/chapter.vtt',
array(
'videoId' => $video->videoId,
'language' => 'en'
)
);
// Get video chapter by language
$chapter = $client->chapters->get($video->videoId, 'en');
//Delete chapter by language
$client->chapters->delete($video->videoId, 'en');
// Create a live stream container
$liveStream = $client->lives->create('Test live');
// Get the RTMP stream key
$streamKey = $liveStream->streamKey;
//// Raw statistics
// List video player sessions
$videoSessions = $client->analyticsVideo->search($video->videoId);
// List video player sessions for the month of July 2018 with pagination
$videoSessionsJuly2018 = $client->analyticsVideo->search($video->videoId, '2018-07', array(), array('currentPage' => 1, 'pageSize' => 100));
// Get video session events for a sessionId
$videoSessionEvents = $client->analyticsSessionEvents->get($videoSessions[0]->session->sessionId);
// List video player sessions
$liveSessions = $client->analyticsLive->search($liveStream->liveStreamId);
// List video player sessions for the month of July 2018 with pagination
$liveSessionsJuly2018 = $client->analyticsLive->search($video->videoId, '2018-07', array(), array('currentPage' => 1, 'pageSize' => 100));
// Get video session events for a sessionId
$liveSessionEvents = $client->analyticsSessionEvents->get($liveSessions[0]->session->sessionId);
// Generate a token for delegated upload
$token = $client->tokens->generate();
/*
*********************************
*********************************
* VIDEO *
*********************************
*********************************
*/
// Show a video
$client->videos->get($videoId);
// List or search videos
$client->videos->search($parameters = array(), $callback = null);
// Create video properties
$client->videos->create($title, $properties = array());
// Upload a video media file
// Create a video, if videoId is null
$client->videos->upload($source, $properties = array(), $videoId = null);
// Create a video by downloading it from a third party
$client->videos->download($source, $title, $properties = array());
// Update video properties
$client->videos->update($videoId, $properties = array());
// Set video public
$client->videos->setPublic($videoId);
// Set video private
$client->videos->setPrivate($videoId);
// Delete video (file and data)
$client->videos->delete($videoId);
// Get last video request Error
$client->videos->getLastError();
// Delegated upload (generate a token for someone to upload a video into your account)
$token = $client->tokens->generate(); // string(3): "xyz"
// ...then upload from anywhere without authentication:
// $ curl https://ws.api.video/upload?token=xyz -F [email protected]
/*
*********************************
* VIDEO THUMBNAIL *
*********************************
*/
// Upload a thumbnail for video
$client->videos->uploadThumbnail($source, $videoId);
// Update video's thumbnail by picking timecode
$client->videos->updateThumbnailWithTimeCode($videoId, $timecode);
// Get last video request Error
$client->videos->getLastError();
/*
*********************************
* VIDEO CAPTIONS *
*********************************
*/
// Get caption for a video
$client->captions->get($videoId, $language);
// Get all captions for a video
$client->captions->getAll($videoId);
// Upload a caption file for a video (.vtt)
$client->captions->upload($source, $properties = array());
// Set default caption for a video
$client->captions->updateDefault($videoId, $language, $isDefault);
// Delete video's caption
$client->captions->delete($videoId, $language);
// Get last video captions request Error
$client->captions->getLastError();
/*
*********************************
* VIDEO CHAPTERS *
*********************************
*/
// Get chapter for a video
$client->chapters->get($videoId, $language);
// Get all chapters for a video
$client->chapters->getAll($videoId);
// Upload a chapter file for a video (.vtt)
$client->chapters->upload($source, $properties = array());
// Delete video's chapter
$client->chapters->delete($videoId, $language);
// Get last video chapters request Error
$client->chapters->getLastError();
/*
*********************************
* PLAYERS *
*********************************
*/
// Get a player
$client->players->get($playerId);
// List players
$client->players->search($parameters = array(), $callback = null);
// Create a player
$client->players->create($properties = array());
// Update player's properties
$client->players->update($playerId, $properties);
// Upload player logo
$client->players->uploadLogo('/path/to/logo.png', $playerId, 'https://api.video');
// Delete a logo
$client->players->deleteLogo($playerId);
// Delete a player
$client->players->delete($playerId);
// Get last players request Error
$client->players->getLastError();
/*
*********************************
*********************************
* LIVE *
*********************************
*********************************
*/
// Show a live
$client->lives->get($liveStreamId);
// List or search lives
$client->lives->search($parameters = array(), $callback = null);
// Create live properties
$client->lives->create($name, $properties = array());
// Update live properties
$client->lives->update($liveStreamId, $properties = array());
// Set live public
$client->lives->setPublic($liveStreamId);
// Set live private
$client->lives->setPrivate($liveStreamId);
// Delete live (file and data)
$client->lives->delete($liveStreamId);
// Get last live request Error
$client->lives->getLastError();
/*
*********************************
* LIVE THUMBNAIL *
*********************************
*/
// Upload a thumbnail for live
$client->lives->uploadThumbnail($source, $liveStreamId);
/*
*********************************
* ANALYTICS *
*********************************
*/
// Search videos analytics between period, filter with tags or metadata
$client->analyticsVideo->search($videoId, $period, $metadata, $parameters);
// Get last video analytics request Error
$client->analyticsVideo->getLastError();
// Search live stream analytics between period, filter with tags or metadata
$client->analyticsLive->search($liveStreamId, $period, $parameters);
// Get last live analytics request Error
$client->analyticsLive->getLastError();
// Get session events analytics
$client->analyticsSessionEvents->search($sessionId, $parameters);
// Get last sesion events analytics request Error
$client->analyticsSessionEvents->getLastError();
shell
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.