从YouTube API显示输出XML - PHP [英] display xml output from youtube api - php

查看:240
本文介绍了从YouTube API显示输出XML - PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我可以通过观看次数(命中)的YouTube频道的视频列表,并与下方

i've found that I can get a list of a youtube channel's videos by viewCount (hits) and limit the results with the link below

<一个href=\"http://gdata.youtube.com/feeds/api/users/edbassmaster/uploads?orderby=viewCount&max-results=5\" rel=\"nofollow\">http://gdata.youtube.com/feeds/api/users/edbassmaster/uploads?orderby=viewCount&max-results=5

这当然会返回一些XML饲料code。我想列出的视频上传到我的一个div网站。

this of course returns some xml feed code. I am trying to list the videos onto my website in a div.

我已经试过:

<?php
    $list = Array(); 
    //get the xml data from youtube 
    $url = "http://gdata.youtube.com/feeds/api/users/edbassmaster/uploads?orderby=viewCount&max-results=5"; 
    $xml = simplexml_load_file($url); 
    //load up the array $list['title'] = $xml->title[0]; 
    $list['title'] = $xml->title[0]; 
    echo $list['title'];
?>

到目前为止,这只是给我的标题XML饲料,如果我尝试 $ XML的&GT;标题[1] 。它不返回任何东西。我如何使用XML提要列出标题和(HREF)其链接到视频?我尝试从XML源2件事,视频和URL的名称。

So far that just gives me the title for the xml feed, if I try $xml->title[1]. It doesn't return anything. How can I use that xml feed to list the titles and (href) link them to the videos? I'm trying to retrieve 2 things from the xml source, the title of the video and the url.

感谢。

推荐答案

事情是这样的:

 <?php
$url = "http://gdata.youtube.com/feeds/api/users/edbassmaster/uploads?orderby=viewCount&max-results=5";
$xml = simplexml_load_file($url);
foreach($xml->entry as $entry){
    echo "Title: ".$entry->title."<br />";
    echo "Link :".$entry->link['href']."<br />";
}
?>

这篇关于从YouTube API显示输出XML - PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆