【问题标题】:Retrive recent videos of multiple YouTube users and order by most recent检索多个 YouTube 用户的最近视频并按最近排序
【发布时间】:2014-11-27 11:40:21
【问题描述】:

正如标题所示,我希望使用 PHP 从 MULTIPLE YouTube 频道中检索最近的视频及其 JSON 数据。我环顾了 stackoverflow,但我找不到用户的回复正是我正在寻找的(即使进行了调整。)

我可以使用此代码从单个用户那里获取最近上传的 youtube 视频。

<?php

$xml = simplexml_load_file("https://gdata.youtube.com/feeds/api/users/1jBoA_hgXTtGgs8OIrfYkg/upload     s");
$json = json_encode($xml);
$videos = json_decode($json, true);

var_dump($videos);

注意:我显示的代码确实有效,但我正在寻找代码以按顺序显示来自多个用户的视频。

提前致谢:)

【问题讨论】:

  • 您需要展示到目前为止您已经尝试过的内容以及出了什么问题。阅读此stackoverflow.com/help/how-to-ask
  • 这样更好吗?注意:我显示的代码确实有效,但我正在寻找代码以按顺序显示来自多个用户的视频。

标签: php video youtube


【解决方案1】:

如果您知道用户的姓名,我猜您知道,您可以简单地将它们放入一个数组中,然后使用您在每次迭代中使用的上述代码对数组进行迭代。

// Array of users (dummy values....)
$users = array("1jBoA_hgXTtGgs8OIrfYkg", "4dfg_hgXTtGgs8OIrfYkg", "6dzgdf_hgXTtGgs8OIrfYkg");

$allVideoLists = array();

// Iterate over each user in the 'users' array one by one
foreach ($users as $thisUser) {
         //Get the video list for this user and create an object from the JSON
         $xml=simplexml_load_file("https://gdata.youtube.com/feeds/api/users/" + $thisUser + "/uploads");
         $json = json_encode($xml);
         $videos = json_decode($json, true);
         //Add this users Video list to the array of all user's video lists
         $allVideoLists[] = $videos
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2018-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多