Reputation: 473
Ok, working on a vimeo based video blog theme for wordpress and rather than lazily ask people to paste the embed code into each video update (via a custom field), I'd rather the user supplied just the video id... basically I can't guarantee that each video is going to be the same height / width so I'm trying to get the embed code directly from vimeo (rather than getting the user to supply) rather than hardcoding a height / width for the iframe (as the theme is going to be responsive and I'm using a small jquery script to resize the videos on the fly)
So far, having tried to butcher Vimeo's own API example, I've got this:
function curl_get($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($curl);
curl_close($curl);
return $return;
}
// Create the URL
$oembed_vid_id = get_field('video_embed_code');
$oembed_url = 'http://vimeo.com/api/v2/video/' . $oembed_vid_id . '.xml';
// Load in the oEmbed XML
$oembed = simplexml_load_string(curl_get($oembed_url));
$embed_code = html_entity_decode($oembed->html);
<?php echo $embed_code ?>
But I get nothing back, have I overlooked something quite basic?
I can confirm that the $oembed_url URL does exist, try any vimeo id and you'll see the relevant xml for it, i.e. here's a video I've plucked from vimeo:
http://vimeo.com/api/v2/video/48198301.xml
Would be fantastic if I could get to grips with this as I'll be able to pull down thumbnails etc. and make use of all that other lovely info tucked away in the xml file.
Upvotes: 0
Views: 7265
Reputation: 14681
From Vimeo's Sample Code, it seems that you are not using the right API.
http://vimeo.com/api/v2/video/
will return the video info fields, but doesn't have a html
field. To get the embed code, use this URL:
$oembed_url = 'http://vimeo.com/api/oembed.xml?url=' . urlencode("http://vimeo.com/$oembed_vid_id");
Upvotes: 1