0

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.

4

1 回答 1

1

Vimeo 的示例代码中,您似乎没有使用正确的 API。

http://vimeo.com/api/v2/video/将返回视频信息字段,但没有html字段。要获取嵌入代码,请使用以下 URL:

$oembed_url = 'http://vimeo.com/api/oembed.xml?url=' . urlencode("http://vimeo.com/$oembed_vid_id");
于 2012-09-10T16:28:43.210 回答