0

So as the title suggests I am looking to use PHP to retrive recent videos and their JSON data from MULTIPLE YouTube channels. I have looked around stackoverflow and I cannot find a reply from a user that is exactly what I am looking for (Even with tweaking.)

I am able to use this code to grab recently uploaded youtube videos from a single user.

<?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);

Note: The code I have shown does work but I am looking for code to display videos from multiple users in order.

Thanks in advance :)

Scott Ansell
  • 43
  • 1
  • 9
  • You need to show what you've tried so far, and what is going wrong. Read this http://stackoverflow.com/help/how-to-ask – rjdown Nov 27 '14 at 11:59
  • Is this better? Note: The code I have shown does work but I am looking for code to display videos from multiple users in order. – Scott Ansell Nov 27 '14 at 12:15

1 Answers1

0

If you know the name of the users, which I am guesing you do, you could simply put them in an array and then iterate over the array using the code you have working above inside each iteration.

// 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
}
Mick
  • 24,231
  • 1
  • 54
  • 120
  • Thanks, but then how would I go about putting all the videos in **ORDER**? – Scott Ansell Nov 30 '14 at 09:49
  • There are quite a few resources that will show you how to sort a PHP array according to a criteria you define yourself. See: http://stackoverflow.com/a/11145568/334402 and http://php.net/manual/en/function.usort.php for example. – Mick Nov 30 '14 at 21:57