Search code examples
phpcssvimeo

Load vimeo hd thumbnails with NEW API


I'm using code similar to this to load thumbnails of vimeo videos.

    <?php

        if(defined('AT_PROXY'))  {
              $aContext = array(
                  'http' => array(
                      'proxy' => AT_PROXY,
                      'request_fulluri' => true,
                  ),
              );
              $cxContext = stream_context_create($aContext);

              $contents = file_get_contents('http://vimeo.com/api/v2/video/'.$main_video.'.php', False, $cxContext);
         } else {
              $contents = file_get_contents('http://vimeo.com/api/v2/video/'.$main_video.'.php');
         }


        $contents = file_get_contents('http://vimeo.com/api/v2/video/'.$main_video.'.php');

        $array = @unserialize(trim($contents));
        $video_thumbnail = str_replace('http://', 'https://',$array[0]["thumbnail_large"]);
    ?>

     <div class="video_thumbnail text-center">

          <img src="<?php echo $video_thumbnail ?>" alt="" class="img-responsive" />

          <div class="play js-play" data-vid="<?php echo $main_video; ?>">
               <span class="glyphicon glyphicon-play play-btn"></span>
          </div>

     </div>

The large thumbnail is 640px

Apparently this is the old API. I should be using the new API if I want to load larger thumbnails.

https://developer.vimeo.com/api

I can't seem to find how to do it with the 'NEW' API.

Does anyone know how to load thumbnails with the new API, are there any examples of how to do it?


Solution

  • Use the new API to fetch video information. For instance go to https://developer.vimeo.com/api/playground/videos/ and put in a video id and make the call.

    It will return a json result. The section 'pictures' will have all available thumbnails you can fetch.

    Here is the pictures section for an authenticated call to https://api.vimeo.com/videos/111096137

    "pictures": {
        "uri": "/videos/111096137/pictures/495591662",
        "active": true,
        "sizes": [
            {
                "width": 100,
                "height": 75,
                "link": "https://i.vimeocdn.com/video/495591662_100x75.jpg"
            },
            {
                "width": 200,
                "height": 150,
                "link": "https://i.vimeocdn.com/video/495591662_200x150.jpg"
            },
            {
                "width": 295,
                "height": 166,
                "link": "https://i.vimeocdn.com/video/495591662_295x166.jpg"
            },
            {
                "width": 640,
                "height": 360,
                "link": "https://i.vimeocdn.com/video/495591662_640x360.jpg"
            },
            {
                "width": 960,
                "height": 540,
                "link": "https://i.vimeocdn.com/video/495591662_960x540.jpg"
            },
            {
                "width": 1280,
                "height": 720,
                "link": "https://i.vimeocdn.com/video/495591662_1280x720.jpg"
            }
        ]
    },
    

    You can use this info to fetch whatever sizes you want.