, ,

Get a thumbnail from the Vimeo API

Grabbing the thumbnail URL for a video hosted on YouTube has always been simple. Just stick the video’s unique ID into a URL and bam- there’s your image. When it came to the Vimeo API, on the other hand, it used to be simple.

Recently Vimeo has been in the process of sunsetting it’s classic “SImple” API, also known as version 2. It seems like some videos still appear on the old API and some don’t. Now grabbing a thumbnail requires an developer app, API access, oAuth, and a huge php library to boot.

Luckily, I stumbled upon this approach from the Drupal community. Contrary to the title of this post, the thumbnail isn’t going to come from the Vimeo Developer API exactly, but instead Vimeo’s oEmbed endpoints.

Whether or not the video is public or private, as long as it is allowed to be embedded, vimeo provides an oEmbed endpoint with useful information about the video, including the thumbnail URL. Just grab the sweet JSON information, pull out the thumbnail URL, and enjoy!

https://gist.github.com/bacoords/77ee4d13dfa76db03981cb4eb0df0c6f

This handy little PHP function takes in the embed URL of a Vimeo video, hits the Vimeo API, grabs the oEmbed data, and spits out the thumbnail URL (or false if there are any issues). Play around with is, and see what other data you can grab.

Learn Modern WordPress Development

I’m sharing the best resources and tutorials for developers building in and on the block editor.


11 responses to “Get a thumbnail from the Vimeo API”

  1. Scott Kondor Avatar

    Thanks a lot! Great code that works without issue.

  2. Spurgeon Avatar
    Spurgeon

    God bless you abundantly dear Brian!!

  3. Hannah Hudson Avatar
    Hannah Hudson

    Thank so much, Brian!!

  4. James Myers Avatar
    James Myers

    Brian you are the man!

  5. Timothy Johns Avatar

    Don’t think I have a way to install Vimeo’s PHP library… this is a lifesaver! Thanks!

  6. vgfr456 Avatar

    Does it still work?

    1. Brian Coords Avatar
      Brian Coords

      As far as I know!

  7. nelsonpatrickr Avatar
    nelsonpatrickr

    Looks like this has actually stopped working for private videos that allow embed. Not sure if there was any notice or documentation about this, but this includes not only Oembed but also their regular video info endpoint: http://vimeo.com/api/v2/video/VIDEOID.json

    It’s pretty disappointing to see this change since now it will require a lot of extra work for anyone who relied on a very simple REST request, given the overhead now for authentication.

    1. Brian Coords Avatar
      Brian Coords

      Thanks for the heads up. I’ll have to take a look- hopefully it’s still working with public videos at the very least. I agree that vimeo is intent on making it extremely difficult to access your videos programmatically.

    2. Garry Byrne Avatar

      There’s a way to fetch the thumbnail without authentication, if you can provide a whitelisted domain in your call. I’ve put some example code here: https://potatopost.co.uk/2020/04/09/getting-a-vimeo-video-thumbnail-using-the-id-or-url/

    3. Brian Coords Avatar
      Brian Coords

      Thanks for sharing Garry! Maybe one day Vimeo will just make our lives easier.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.