检索多个YouTube用户的近期视频并按最新订单排序

时间:2014-11-27 11:40:22

标签: php video youtube

因为标题表明我希望使用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);

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

提前致谢:)

1 个答案:

答案 0 :(得分:0)

如果你知道用户的名字,我猜你做了,你可以简单地将它们放在一个数组中,然后使用你在每次迭代中使用的代码迭代数组。

// 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
}
相关问题