Search code examples
phpvimeovimeo-api

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!


Solution

  • 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.