【问题标题】:codeigniter and youtube api - xml woescodeigniter 和 youtube api - xml 问题
【发布时间】:2011-11-03 16:25:59
【问题描述】:

我正在开发一个使用 codeigniter 和 youtube api 的项目,我提出了一个视频请求,我收到了一些 XML,我的问题是我不知道如何处理所述 XML,或者更多到点如何解析它,以便我可以得到我想要的值,我得到它的 XML,

<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005'
xmlns:yt='http://gdata.youtube.com/schemas/2007'>
    <id>http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc</id>
    <published>2010-11-29T21:28:22.000Z</published>
    <updated>2011-03-14T12:01:51.000Z</updated>
    <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Travel' label='Travel &amp; Events'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Barney'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Harwood'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Interview'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='children&apos;s'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='bafta'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='awards'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='2010'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='red'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='carpet'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='host'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='tv'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='television'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='show'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='presenter'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='prank'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='patrol'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='the'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='sorcerer&apos;s'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='apprentice'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='bbc'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='cbbc'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='bear'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='behaving'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='badly'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='nev'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='smile'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='totally'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='doctor'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='who'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='basil&apos;s'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='swap'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='shop'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='basil'/>
    <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='brush'/>
    <title type='text'>Barney Harwood Interview</title>
    <content type='text'>Barney Harwood Interview - We talk to children's TV presenter Barney Harwood on the red carept, ahead of his duties as host for the Children's BAFTA Awards 2010 in London. Presented by Michael Kurn Camera and Post by Russell Nelson</content>
    <link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=x33JD3-hXHc&amp;feature=youtube_gdata'/>
    <link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc/responses'/>
    <link rel='http://gdata.youtube.com/schemas/2007#video.ratings' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc/ratings'/>
    <link rel='http://gdata.youtube.com/schemas/2007#video.complaints' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc/complaints'/>
    <link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc/related'/>
    <link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=x33JD3-hXHc'/>
    <link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc'/>
    <author>
        <name>LeicesterSquareTV</name>
        <uri>http://gdata.youtube.com/feeds/api/users/leicestersquaretv</uri>
    </author>
    <gd:comments>
        <gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc/comments' countHint='5'/>
    </gd:comments>
    <yt:hd/>
    <media:group>
        <media:category label='Travel &amp; Events' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Travel</media:category>
        <media:content url='http://www.youtube.com/v/x33JD3-hXHc?version=3&amp;f=videos&amp;d=Ac2cvuTKQbM_TEZ_NAvfWNEO88HsQjpE1a8d1GxQnGDm&amp;app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='150' yt:format='5'/>
        <media:content url='rtsp://v4.cache7.c.youtube.com/CkULENy73wIaPAl3XKF_D8l9xxMYDSANFEgGUgZ2aWRlb3NyIQHNnL7kykGzP0xGfzQL31jRDvPB7EI6RNWvHdRsUJxg5gw=/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='150' yt:format='1'/>
        <media:content url='rtsp://v2.cache5.c.youtube.com/CkULENy73wIaPAl3XKF_D8l9xxMYESARFEgGUgZ2aWRlb3NyIQHNnL7kykGzP0xGfzQL31jRDvPB7EI6RNWvHdRsUJxg5gw=/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='150' yt:format='6'/>
        <media:description type='plain'>Barney Harwood Interview -We talk to children's TV presenter Barney Harwood on the red carept, ahead of his duties as host for the Children's BAFTA Awards 2010 in London. Presented by Michael Kurn
        Camera and Post by Russell Nelson
        </media:description>
        <media:keywords>Barney, Harwood, Interview, children's, bafta, awards, 2010, red, carpet, host, tv, television, show, presenter, prank, patrol, the, sorcerer's, apprentice, bbc, cbbc, bear, behaving, badly, nev, smile, totally, doctor, who, basil's, swap, shop, basil, brush
        </media:keywords>
        <media:player url='http://www.youtube.com/watch?v=x33JD3-hXHc&amp;feature=youtube_gdata_player'/>
        <media:thumbnail url='http://i.ytimg.com/vi/x33JD3-hXHc/0.jpg' height='360' width='480' time='00:01:15'/>
        <media:thumbnail url='http://i.ytimg.com/vi/x33JD3-hXHc/1.jpg' height='90' width='120' time='00:00:37.500'/>
        <media:thumbnail url='http://i.ytimg.com/vi/x33JD3-hXHc/2.jpg' height='90' width='120' time='00:01:15'/>
        <media:thumbnail url='http://i.ytimg.com/vi/x33JD3-hXHc/3.jpg' height='90' width='120' time='00:01:52.500'/>
        <media:title type='plain'>Barney Harwood Interview</media:title><yt:duration seconds='150'/>
    </media:group>
    <gd:rating average='5.0' max='5' min='1' numRaters='1' rel='http://schemas.google.com/g/2005#overall'/>
    <yt:statistics favoriteCount='0' viewCount='1141'/>
</entry>

具体如何获取缩略图?

【问题讨论】:

    标签: php xml codeigniter youtube-api


    【解决方案1】:

    我建议你开始阅读simpleXML

    如果这不适合你,你可以找到一个更容易理解但更简单的教程here

    【讨论】:

      【解决方案2】:

      我不确定你是否在使用我开发的库。 Here is the link。如果你是,那么有一个“alt”参数,你可以将它传递到你的库调用中,让你指定你希望如何返回数据。如果设置为 JSON,则可以使用 PHP 内置的 json_decode 函数。

      即使您不使用我的库,您仍然可以使用 alt 参数,只需在您的 GET uri 中指定它即可。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-24
        • 1970-01-01
        • 2016-02-27
        • 2016-11-09
        • 2011-03-31
        • 2011-12-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多