好吧,为wordpress开发一个基于vimeo的视频博客主题,而不是懒惰地要求人们将嵌入代码粘贴到每个视频更新中(通过自定义字段),我宁愿用户只提供视频id……基本上,我不能保证每个视频的高度/宽度都是一样的,所以我尝试直接从vimeo获取嵌入代码(而不是让用户提供),而不是硬编码iframe的高度/宽度(因为主题将是响应性的,我正在使用一个小的jquery脚本来动态调整视频的大小)
到目前为止,在尝试使用Vimeo自己的API示例之后,我得到了以下结果:
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 ?>但是我什么也得不到,我是不是忽略了一些非常基本的东西?
我可以确认vimeo确实存在,尝试任何$oembed_url id,您都会看到它的相关xml,例如,这是我从Vimeo上摘录的视频:
http://vimeo.com/api/v2/video/48198301.xml
如果我能掌握这一点就太好了,因为我将能够拉下缩略图等,并利用隐藏在xml文件中的所有其他可爱的信息。
发布于 2012-09-11 00:28:43
从Vimeo's Sample Code上看,您似乎没有使用正确的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");https://stackoverflow.com/questions/12355300
复制相似问题