Albert
Albert

Reputation: 1526

How to retrieve video URLs by video ID from my own Vimeo account

I have a Vimeo PRO account with a bunch of videos, and what I want is use PHP to retrieve the direct link to a video (so its mp4 file URL that you can get through the settings sections in Vimeo's website) providing the video ID.

I've already created a Vimeo app in Vimeo's developer site, so I have all the required credentials. But Vimeo's documentation is a nightmare and you end up jumping from link to link trying to find something in order to end up where you started...

I've found this example in SO but when I follow it I end up reaching a wall because the API it uses apparently doesn't work anymore, so in order to find out how to adapt it I use the current documentation, which takes me to the loophole mentioned above.

So, could anyone point me to (or provide) some real world code for what I'm trying to accomplish? It sounds like it should be pretty simple but I can't figure it out. The biggest issue I have is that all the examples I see are meant for accessing others videos, but I want access to mine.

I've been looking at the API's github page but I can't figure out how to initiate the API with my credentials and how to get a video's information providing its ID, I don't see an example for that.

Any help would be much appreciated!

Upvotes: 4

Views: 4763

Answers (2)

Marco Floriano
Marco Floriano

Reputation: 349

I´m facing the same problems trying to get some real world code in order to learn how to use the new API.

Here are an example of how to get a VIDEO URL:

<?php

    require("includes/vimeo/autoload.php");
    use Vimeo\Vimeo;

    $client_id = 'Client Identifier';
    $client_secret = 'Client Secrets';
    $access_token = 'Token';

    $vimeo = new Vimeo($client_id, $client_secret, $access_token);
    $response = $vimeo->request("/videos/video_id");
    echo $response["body"]["link"];

?>  

Making an list from all videos of an album, sorted alphabetic, 50 per page (2 pages in this case, 83 videos):

<?php

    require("includes/vimeo/autoload.php");
    use Vimeo\Vimeo;

    $client_id = 'Client Identifier';
    $client_secret = 'Client Secrets';
    $access_token = 'Token';

    $vimeo = new Vimeo($client_id, $client_secret, $access_token);

    /* Get the list of videos in an Album */
    $pages = 2;
    for($i = 1; $i <= $pages; $i++) {
    $format = "/me/albums/3004651/videos?per_page=50&sort=alphabetical&page=" . $i;
    $response = $vimeo->request($format);
     foreach ($response['body']['data'] as $video) {
        echo str_replace("/videos/", "", $video['uri']);
        echo "<br />";
    }
 }  

?>  

More code examples would be good. Hope it helps.

Upvotes: 4

Dashron
Dashron

Reputation: 3998

We're working on improving the docs! In the next couple of months they are getting an overhaul to be more "feature" based and less "api" based.

In the meanwhile, PRO users have access to their own video files on every video response. Lists of videos in channels, lists of your videos, direct video links etc.

  1. Start by using the official PHP library: https://github.com/vimeo/vimeo.php
  2. Get your access token (through redirect for external Vimeo users, through the developer site for your own account) and put it into the library
  3. Your videos can be located through $videos = $lib->request('/me/videos');
  4. Find the file information (containing more than the url) at $videos['body']['data'][$array_index]['files']

For now I recommend writing a quick script and dumping out the list of files to help determine the rest of the logic. Make sure to pick your file based on the dimensions of the video, because HD could mean either 720 or 1080p.

Upvotes: 1

Related Questions