Skip to content

apivideo/api.video-php-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api.video PHP API client

api.video is an API that encodes on the go to facilitate immediate playback, enhancing viewer streaming experiences across multiple devices and platforms. You can stream live or on-demand online videos within minutes.

Installation

composer require api-video/php-api-client

Initialize api.video client

Due to PHP PSR support, you must initialize the client with 3 to 5 arguments:

  1. Base URI, which can be either https://sandbox.api.video or https://ws.api.video
  2. Your API key, available on your account
  3. HTTP client
  4. (Request factory)
  5. (Stream factory)

Note : If the HTTP client also implements RequestFactoryInterface and StreamFactoryInterface, then it is not necessary to pass this object in 4th and 5th argument.

Symfony HTTP client example

The Symfony HTTP client has the triple advantage of playing the role of HTTP client, but also of request factory and stream factory. It is therefore sufficient to pass it as an argument 3 times.

$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$client = new \ApiVideo\Client(
    'https://sandbox.api.video',
    'YOUR_API_TOKEN',
    $httpClient
);

Public endpoints

Some endpoints don't require authentication. These one can be called with a Client instantiated with a null API token:

$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$client = new \ApiVideo\Client(
    'https://sandbox.api.video',
    null,
    $httpClient
);

Cookbook

In the following examples the $client must already be initialized.

Create a video

$payload = (new VideoCreationPayload())
    ->setTitle('Test video creation');

$video = $client->videos()->create($payload);

Upload a video

$payload = (new VideoCreationPayload())
    ->setTitle('Test video creation');

$video = $client->videos()->create($payload);

$this->client->videos()->upload(
    $video->getVideoId(),
    new SplFileObject(__DIR__.'/../earth.mp4')
);

Chunks

The video is automatically split into 1 Mb chunks.

To modify the size of the chunks, fill in the last argument $contentRange as follows:

  • bytes 0-{size}/0 where {size} is the size of the chunk.

For example : bytes 0-500000/0 for 500 Kb chunks.

API Endpoints

All URIs are relative to https://ws.api.video.

CaptionsApi

Retrieve an instance of CaptionsApi

// The $client must already be initialized
$captions = $client->captions();

Endpoints

Method HTTP request Description
delete DELETE /videos/{videoId}/captions/{language} Delete a caption
list GET /videos/{videoId}/captions List video captions
get GET /videos/{videoId}/captions/{language} Show a caption
update PATCH /videos/{videoId}/captions/{language} Update caption
upload POST /videos/{videoId}/captions/{language} Upload a caption

ChaptersApi

Retrieve an instance of ChaptersApi

// The $client must already be initialized
$chapters = $client->chapters();

Endpoints

Method HTTP request Description
delete DELETE /videos/{videoId}/chapters/{language} Delete a chapter
list GET /videos/{videoId}/chapters List video chapters
get GET /videos/{videoId}/chapters/{language} Show a chapter
upload POST /videos/{videoId}/chapters/{language} Upload a chapter

LiveStreamsApi

Retrieve an instance of LiveStreamsApi

// The $client must already be initialized
$liveStreams = $client->liveStreams();

Endpoints

Method HTTP request Description
delete DELETE /live-streams/{liveStreamId} Delete a live stream
deleteThumbnail DELETE /live-streams/{liveStreamId}/thumbnail Delete a thumbnail
list GET /live-streams List all live streams
get GET /live-streams/{liveStreamId} Show live stream
update PATCH /live-streams/{liveStreamId} Update a live stream
create POST /live-streams Create live stream
uploadThumbnail POST /live-streams/{liveStreamId}/thumbnail Upload a thumbnail

PlayerThemesApi

Retrieve an instance of PlayerThemesApi

// The $client must already be initialized
$playerThemes = $client->playerThemes();

Endpoints

Method HTTP request Description
delete DELETE /players/{playerId} Delete a player
deleteLogo DELETE /players/{playerId}/logo Delete logo
list GET /players List all players
get GET /players/{playerId} Show a player
update PATCH /players/{playerId} Update a player
create POST /players Create a player
uploadLogo POST /players/{playerId}/logo Upload a logo

RawStatisticsApi

Retrieve an instance of RawStatisticsApi

// The $client must already be initialized
$rawStatistics = $client->rawStatistics();

Endpoints

Method HTTP request Description
listLiveStreamSessions GET /analytics/live-streams/{liveStreamId} List live stream player sessions
listSessionEvents GET /analytics/sessions/{sessionId}/events List player session events
listVideoSessions GET /analytics/videos/{videoId} List video player sessions

UploadTokensApi

Retrieve an instance of UploadTokensApi

// The $client must already be initialized
$uploadTokens = $client->uploadTokens();

Endpoints

Method HTTP request Description
deleteToken DELETE /upload-tokens/{uploadToken} Delete an upload token
list GET /upload-tokens List all active upload tokens.
getToken GET /upload-tokens/{uploadToken} Show upload token
createToken POST /upload-tokens Generate an upload token

VideosApi

Retrieve an instance of VideosApi

// The $client must already be initialized
$videos = $client->videos();

Endpoints

Method HTTP request Description
delete DELETE /videos/{videoId} Delete a video
get GET /videos/{videoId} Show a video
getStatus GET /videos/{videoId}/status Show video status
list GET /videos List all videos
update PATCH /videos/{videoId} Update a video
pickThumbnail PATCH /videos/{videoId}/thumbnail Pick a thumbnail
uploadWithUploadToken POST /upload Upload with an upload token
create POST /videos Create a video
upload POST /videos/{videoId}/source Upload a video
uploadThumbnail POST /videos/{videoId}/thumbnail Upload a thumbnail

WebhooksApi

Retrieve an instance of WebhooksApi

// The $client must already be initialized
$webhooks = $client->webhooks();

Endpoints

Method HTTP request Description
delete DELETE /webhooks/{webhookId} Delete a Webhook
get GET /webhooks/{webhookId} Show Webhook details
list GET /webhooks List all webhooks
create POST /webhooks Create Webhook

Models

Tests

In order to run the PhpUnit tests, it is necessary to enter two variables in the command line:

  • BASE_URI (for example : https://sandbox.api.video)
  • API_KEY

These identifiers must belong to a real Api.video account.

$ BASE_URI="" API_KEY="..." vendor/bin/phpunit