开发者

Retrieve vimeo video information from xml

开发者 https://www.devze.com 2023-04-11 07:56 出处:网络
I want to get data from XML API output from Vimeo. In Vimeo if we load this URL:http://vimeo.com/api/v2/video/30055721.xml the video ID is 30055721, it will output the XML data in the browser (single

I want to get data from XML API output from Vimeo.

In Vimeo if we load this URL: http://vimeo.com/api/v2/video/30055721.xml the video ID is 30055721, it will output the XML data in the browser (single-line XML chunk):

<?xml version="1.0" encoding="UTF-8"?><videos><video><id>30055721</id><title>[MV]I-ny(아이니) 뮤직비디오</title><description>눈부신 가을 하늘을 닮은 목소리의 주인공 '아이니(i-ny)',  &lt;br /&gt;  그녀의 이름을 노래하다.</description><url>http://vimeo.com/30055721</url><upload_date>2011-10-04 22:34:19</upload_date><mobile_url>http://vimeo.com/m/30055721</mobile_url><thumbnail_small>http://b.vimeocdn.com/ts/201/671/201671639_100.jpg</thumbnail_small><thumbnail_medium>http://b.vimeocdn.com/ts/201/671/201671639_200.jpg</thumbnail_medium><thumbnail_large>http://b.vimeocdn.com/ts/201/671/201671639_640.jpg</thumbnail_large><user_id>2991448</user_id><user_name>Deviljoon</user_name><user_url>http://vimeo.com/user2991448</user_url><user_portrait_small>http://b.vimeocdn.com/ps/217/387/2173872_30.jpg</user_portrait_small><user_portrait_medium>http://b.vimeocdn.com/ps/217/387/2173872_75.jpg</user_portrait_medium><user_portrait_large>http://b.vimeocdn.com/ps/217/387/2173872_100.jpg</user_portrait_large><user_portrait_huge>http://b.vimeocdn.com/ps/217/387/2173872_300.jpg</user_portrait_huge><stats_number_of_likes>3</stats_number_of_likes><stats_number_of_plays>542</stats_number_of_plays><stats_number_of_comments>0</stats_number_of_comments><duration>235</duration><width>1280</width><height>720</height><tags>I-ny, 아이니, 뮤직비디오, m开发者_Go百科usic video, MV, kpop, k-pop, 550d</tags><embed_privacy>anywhere</embed_privacy></video></videos> 

But I want to retrieve data in the XML field dynamically to show it in my webpage.


Check out this article for a complete run through:

http://ditio.net/2008/06/19/using-php-curl-to-read-rss-feed-xml/

This should give you a good idea about how to fetch the XML contents into your PHP script, then parse the contents of the XML into your PHP. You will need to make some adaptations to the process of parsing the feed, specific to the vimeo output, but you should be able to do this simply by having a play.

e.g. the below will output the ID.

$ch = curl_init("http://vimeo.com/api/v2/video/30055728.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$xml= new SimpleXmlElement($data, LIBXML_NOCDATA);
echo "<strong>".$xml->video->id."</strong>";

Once $xml has been established, simply change $xml->video->id to whichever node you want (crucually the 'id' section').

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号