Hi.
I'd like to manage to get data
from YouTube Data API.
xml:
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gml='http://www.opengis.net/gml' xmlns:georss='http://www.georss.org/georss' xmlns:media='http://search.yahoo.com/mrss/' xmlns:yt='http://gdata.youtube.com/schemas/2007' xmlns:gd='http://schemas.google.com/g/2005'>
<id>http://gdata.youtube.com/feeds/api/videos?start-index=20&max-results=1&vq=funny+dogs</id>
<updated>2008-03-10T17:10:48.946Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
<title type='text'>YouTube Videos matching query: funny dogs</title>
<logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo>
<link rel='alternate' type='text/html' href='http://www.youtube.com'/>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos'/>
<link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?start-index=20&max-results=1&vq=funny+dogs'/>
<link rel='previous' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?start-index=19&max-results=1&vq=funny+dogs'/>
<link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?start-index=21&max-results=1&vq=funny+dogs'/>
<author>
<name>YouTube</name>
<uri>http://www.youtube.com/</uri>
</author>
<generator version='beta' uri='http://gdata.youtube.com/'>YouTube data API</generator>
<openSearch:totalResults>71511</openSearch:totalResults>
<openSearch:startIndex>20</openSearch:startIndex>
<openSearch:itemsPerPage>1</openSearch:itemsPerPage>
<entry>
<id>http://gdata.youtube.com/feeds/api/videos/haD8RGdX2U0</id>
<published>2007-01-15T02:56:08.000-08:00</published>
<updated>2008-03-09T10:12:11.000-07:00</updated>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Puppies'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Pets'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Dogs'/>
<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/keywords.cat' term='Funny'/>
<category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Comedy' label='Comedy'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Animals'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Cute'/>
<title type='text'>FUNNY DOGS 6</title>
<content type='text'>FUNNY DOGS 6 - more of the funniest pet pics on YouTube. Enjoy!</content>
<link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=haD8RGdX2U0'/>
<link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/haD8RGdX2U0/related'/>
<link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/haD8RGdX2U0'/>
<author>
<name>postingmyvids</name>
<uri>http://gdata.youtube.com/feeds/api/users/postingmyvids</uri>
</author>
<media:group>
<media:title type='plain'>FUNNY DOGS 6</media:title>
<media:description type='plain'>FUNNY DOGS 6 - more of the funniest pet pics on YouTube. Enjoy!</media:description>
<media:keywords>Animals, Cute, Dogs, Funny, Pets, Puppies</media:keywords>
<yt:duration seconds='105'/>
<media:category label='Comedy' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Comedy</media:category>
<media:content url='rtsp://rtsp2.youtube.com/ChoLENy73wIaEQlN2VdnRPyghRMYDSANFEgGDA==/0/0/0/video.3gp' type='video/3gpp' medium='video' isDefault='true' expression='full' duration='105' yt:format='1'/>
<media:content url='rtsp://rtsp2.youtube.com/ChoLENy73wIaEQlN2VdnRPyghRMYESARFEgGDA==/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='105' yt:format='6'/>
<media:player url='http://www.youtube.com/watch?v=haD8RGdX2U0'/>
<media:thumbnail url='http://img.youtube.com/vi/haD8RGdX2U0/2.jpg' height='97' width='130' time='00:00:52.500'/>
<media:thumbnail url='http://img.youtube.com/vi/haD8RGdX2U0/1.jpg' height='97' width='130' time='00:00:26.250'/>
<media:thumbnail url='http://img.youtube.com/vi/haD8RGdX2U0/3.jpg' height='97' width='130' time='00:01:18.750'/>
<media:thumbnail url='http://img.youtube.com/vi/haD8RGdX2U0/0.jpg' height='240' width='320' time='00:00:52.500'/>
</media:group>
<yt:statistics viewCount='358810'/>
<yt:noembed/>
<gd:rating min='1' max='5' numRaters='363' average='3.80'/>
</entry>
</feed>
I tried with:
$doc = new DOMDocument();
$doc->load('http://gdata.youtube.com/feeds/api/videos?vq=funny+dogs&start-index=20&max-results=1');
//$uri = $doc->documentElement->lookupnamespaceURI('media');
//var_dump($uri);
$xp = new domxpath($doc);
$xp->registerNamespace('media','http://search.yahoo.com/mrss');
$totalResults = $xp->query('/def:feed/def:entry/media:group');
var_dump($totalResults->item(0));
I'm using Visual XPath
but it doesn't work
Can you help me, please ?
Bye