I am trying to output the image thumbnail for Vimeo videos embedded on my wordpress site using PHP. The Vimeo videos have domain level privacy.
It looks like Vimeo have updated their API, as I've tried the suggestions in other answers posted here a few years ago, but none of these are working. I've looked through their new API and can't seem to get my head around it.
Specifically, I've tried a few variations of this:
<?php
$imgid = 6271487;
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$imgid.php"));
echo $hash[0]['thumbnail_medium'];
This always retruns a form of fatal error.
Any help on the best way of achieving this would be greatly appreciated!
For completeness, I contacted Vimeo and they supplied the below which seems to work perfectly:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://vimeo.com/api/oembed.json?url=https://vimeo.com/VIDEO_ID",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
"Referer: REFERER_URL"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
A few things: First, that API with the path /api/v2/video/
, has been deprecated and replaced by the "new" API, released a couple of years back.
Second: The old API only supported the extensions .xml
and .json
, returning a response in those respective formats; .php
is not supported by the old API.
To get a video's thumbnail, you'll need to use the new API, or if the video is public and embeddable use oEmbed. Using the Vimeo PHP library, a request to get a video's metadata would look like this:
$videoId = '6271487';
$response = $client->request('/videos/'+$videoId+'/pictures', array(), 'GET');
print_r($response);
An oEmbed request would look like this (expressed as curl, note that Vimeo's oEmbed implementation will only return json
or xml
):
curl -X GET 'https://vimeo.com/api/oembed.json?url=https://vimeo.com/6271487'
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With