/
API

Processing thumbnail images and meta information from Vimeo

19. 09. 2020

When embedding videos from Vimeo into a page (as an HTML embed), we may often want to also get the image and other useful information such as video length, full title, author, and so on.

Fortunately, Vimeo provides a simple HTTP API from which we can read all the data based on the video token.

To avoid having to write the API yourself, just use ready package, which integrates the API completely.

You install the package with the command:

``shell composer require baraja-core/vimeo-video-api


It is easy to use. You create an instance of the `\Baraja\VimeoAPI\VimeoVideoAPI` service to communicate with Vimeo according to the documentation, call the `getInfo()` method, pass the video token, and get the details as a `VideoInfo` entity from which all available information can be read (not all information is always available for every video).

This way you can query even private and publicly unavailable videos. But you always need to know their token.

Listing all available information
---------

A basic way to use the library looks like this:

```php
$api = new \Baraja\VimeoAPI\VimeoVideoAPI;

$token = 0; // Video token as integer
$info = $api->getInfo($token);

echo var_dump($info); // dumps everything

// Dumps the length of the video in seconds:
echo 'Video length is: ' . $info->getDuration();

The $info variable stores all the descriptive information about a particular video. For an overview of all available methods see the implementation.

Jan Barášek   Více o autorovi

Autor článku pracuje jako seniorní vývojář a software architekt v Praze. Navrhuje a spravuje velké webové aplikace, které znáte a používáte. Od roku 2009 nabral bohaté zkušenosti, které tímto webem předává dál.

Rád vám pomůžu:

V jiných jazycích

1.
2.