【问题标题】:Getting Youtube videos using json and php使用 json 和 php 获取 Youtube 视频
【发布时间】:2011-11-14 02:01:53
【问题描述】:

我正在尝试从 Youtube API 获取视频网址和标题。一切正常,但我无法显示数据 - 我只想使用 json 和 php 显示视频的 url 和标题。

我的代码:

 <?php
$get = file_get_contents("http://gdata.youtube.com/feeds/api/videos?vq=cod&orderby=viewCount&max-results=1&start-index=1&alt=json");
$decode = json_decode($get, TRUE); // TRUE for in array format

foreach($decode as $res) { 

echo $res['title']['$t'];
}
?>

【问题讨论】:

  • 您在三分钟前才提出问题 - 有时可能需要半小时、一个小时、一天或更长时间才能有人回答您的问题。请耐心等待。
  • 好的,我的问题是如何获取数据?此查询不起作用。我认为我没有使用正确的标签($res['title']['$t']),我完全糊涂了!访问这个网址找出答案:gdata.youtube.com/feeds/api/…

标签: php json youtube


【解决方案1】:

对于本示例,您实际上并不需要 foreach 循环,因为只有一个返回结果,但对于多个结果,您需要执行以下操作...

foreach ($decode['feed']['entry'] as $entry) {
    echo '<a href="' . $entry['link'][0]['href'] . '">' . $entry['title']['$t'] . '</a><br />';
}

【讨论】:

    猜你喜欢
    • 2011-10-12
    • 2020-11-05
    • 2011-06-13
    • 2013-05-14
    • 2012-03-28
    • 2011-11-05
    • 2012-04-15
    • 2011-03-24
    • 2014-01-26
    相关资源
    最近更新 更多