DEPRECATION WARNING: this SDK is deprecated and will no longer be maintained. It has been replaced by the PHP API client. Please use it instead.

https://github.com/apivideo/php-sdk

Introduction

A PHP SDK for running api.video. Full code and specs can be found at: https://github.com/apivideo/php-sdk

Installation

composer require api-video/php-sdk

Quick Start

<?php

require_once __DIR__ . '/vendor/autoload.php';

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

Video

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

Live Streaming

// Create a live stream container
$liveStream = $client->lives->create('Test live');
// Get the RTMP stream key
$streamKey = $liveStream->streamKey;

Captions

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


Chapters


// Get video chapter by language
$chapter = $client->chapters->get($video->videoId, 'en');

//Delete chapter by language
$client->chapters->delete($video->videoId, 'en');

Player

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

Statistics and Analytics

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


Did this page help you?