Ask your WordPress questions! Pay money and get answers fast! (more info)

Get Thumbnail of Private Vimeo Videos WordPress


I was able to get thumbnail for normal videos. But getting error for private videos.

I need a proper function to get thumbnails in videos that is set to mark as private on vimeo.

The videos are embeddable on my website just getting errors on thumbnail

Example Video:

The code I for free video:
// Get And Cache Vimeo Thumbnails
function get_vimeo_thumb($vURL, $size = 'thumbnail_small') {
$pieces = explode("/", $vURL);
$id = end($pieces);

if(get_transient('vimeo_' . $size . '_' . $id)) {
$thumb_image = get_transient('vimeo_' . $size . '_' . $id);
} else {
$json = json_decode(file_get_contents( "" . $id . ".json" ));
$thumb_image = $json[0]->$size;
set_transient('vimeo_' . $size . '_' . $id, $thumb_image, 2629743);
return $thumb_image;

But vimeo said I need add auth, key, secret in head see here

Anyone how to improve this function add authentication information so I can private video thumbs.

Answers (3)


Luis Abarca answers:

Hi, you should use Vimeo API to get private videos.

Take a look

// file: path-to-get-token.php or inside a plugin
// You need Vimeo API
require 'path-to-your-lib/vimeo/vimeo.php';

// Get this from your account
$vimeo_client_id = 'xxxxx';
$vimeo_client_secret = 'xxxxxxxxxxx';

// This has to be generated on your site, plugin or theme
$vimeo_token = 'xxxxxx';

$callback_url = 'http://yourdomain/path-to-get-token.php';

// If you don't have a token yet
if ( ! empty( $vimeo_client_id ) && ! empty( $vimeo_client_secret ) ) {
// Create vimeo API object with data
$vimeo = new Vimeo( $vimeo_client_id, $vimeo_client_secret );

$_SESSION['state'] = $state = base64_encode(openssl_random_pseudo_bytes(30));

// Create URL for special link call and our callback url
$vimeo_oauth_url = $vimeo->buildAuthorizationEndpoint($callback_url, 'private', $state);

echo '<a href="' . $vimeo_oauth_url . '">Authenticate on Vimeo</a>';

* Handle Vimeo response for token
if ( isset($_GET['code']) && ! empty($_GET['code']) ) {
$code = $_GET['code'];
$state = $_GET['state'];

$vimeo_rquest = $vimeo->accessToken($code, $callback_url);

if ($vimeo_rquest['status'] == 200) {
* Vimeo API token
* Save it on database or transient
$vimeo_token = $vimeo_rquest['body']['access_token'];

// Will save it on this session for now
$_SESSION['access_token'] = $vimeo_token;
} else {
echo "Unsuccessful authentication";

$video_id = '12345';

$vimeo = new Vimeo( $vimeo_client_id, $vimeo_client_secret );

$vimeo->setToken( $vimeo_token );

$result = $vimeo->request('/videos/' . $video_id);

// Video width and height
$video_w = $result['body']['width'];
$video_h = $result['body']['height'];

// Data for thumbnail with index 1
$thumb_data = $result['body']['pictures'][1];

// This is your thumbnail URL
$thumb_url = $thumb_data['link'];

Jihan Ahmed comments:

Can you help me in implementing this I am getting fatal error
I will increase it to $20.

Jihan Ahmed comments:

What's your email or skype so I can send you login info. Even if you are confident I can set it to live domain.

Do we need the compete it library of vimeo.php or part of it.

Luis Abarca comments:

Sure, you have to download vimeo for PHP from github on a folder inside your theme files

Luis Abarca comments:

[email protected] / luis_abarcag

Jihan Ahmed comments:

added on skype. I have added the vimeo.php already you can see on files.


Reigel Gallarde answers:

hello, can you give me a sample url of a private video? I want to test it.

Reigel Gallarde comments:

also, you said that the videos are embeddable on your website, can you give me the code of the embed...

Jihan Ahmed comments:

Jihan Ahmed comments:
Directly embeddable in WordPress Though I used oembed function

Code 1:<div class="video-excerpt">
$video_id = get_post_meta( get_the_ID(), '_video_id', true );
if ( ! empty( $video_id ) ) {
$video_thumb = get_video_thumbnail();
$video_desc = get_post_meta( get_the_ID(), '_video_description', true );

echo '<a rel="wp-video-lightbox" href="'.$video_id.'?width=auto&amp;height=auto" title="'.$video_desc.'"><img src="'.$video_thumb.'" class="video_lightbox_anchor_image" alt="Peter Liljensten"><img class="cs-icon" src="'.get_stylesheet_directory_uri().'/img/s-v-icon.gif" width="490" height="138" alt="Video Icon"></a>';

Code 2:
$video_id = get_post_meta( get_the_ID(), '_video_id', true );
if ( ! empty( $video_id ) ) {
$video_embed_code = wp_oembed_get(''.$video_id.'');
echo '<div class="iframe-flexible-container">';
echo $video_embed_code;
echo '</div>';

Reigel Gallarde comments:

Well, I'm not really sure how you would use this, but here's what I come up with...

I have two functions here:
(for readability)

get_vimeo_thumb function will return an array something like this with var_dump:

array(4) {
["1280"]=> string(47) ""
["960"]=> string(46) ""
["640"]=> string(46) ""
["base"]=> string(38) ""

you can use it something like this

$id = '220234391';
$img = get_vimeo_thumb($id);
echo '$img = get_vimeo_thumb(' . $id . ');';
echo '<br>';

foreach ( $img as $key => $img_url ){
echo '<br>';
echo '<br>';
echo '<br>$img[' . $key . '] : ';
echo $img_url;
echo '<br><img src="' . $img_url . '" >';

sample output

Jihan Ahmed comments:

It's working like charm. Thanks already.
Few Questions: 1. How can I target specific thumb I see they are all in array.
2. I see you are getting code from player bypassing authentication. So, If embed this link in custom field within wp I see no way to get only ID 220234391. Hence I will stick to your solution and use Iframes for embedding.

I will ask the client to put only. And implode last part

Now I ask you: How do I target specific img size?
Can you add the explode and cache image from this function to your function so we will get from this url

That's all. Thanks again.

Jihan Ahmed comments:

I need to get on thumb at a time. I think base thumb 640 will work for me. So, just give me a clean code for that. I assume we can bypass foreach loop. Do we need get_string_between function?

Thanks !

Jihan Ahmed comments:

Sorry we have got a problem.... the function does not work with most of videos. Can give these ID's a try plz

Reigel Gallarde comments:

I'm editing the demo page... so it's not working right now.

Jihan Ahmed comments:

No. as you see this videos are marked as private links and embed anywhere. This is privacy setting. I have the auth keys if you need.

Jihan Ahmed comments:

Hi, Were you able to produce any result plz?


Cesar Contreras answers:

You need the API Key to get the information of the private videos.

Cesar Contreras comments:

It would be fair to pay the same as you offer on this site:

Jihan Ahmed comments:

I will.

Jihan Ahmed comments:

If anyone can give me working code.

Cesar Contreras comments:

Of course. Sorry if you bothered with that but I saw your other post and it is unfair to pay less here as it is the same problem.

I have not used the Vimeo API, so I can not give you the solution ): I just know that for the private videos of uses the API and its Key.

Luck with your solution.