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 :)

2
  • You need to show what you've tried so far, and what is going wrong. Read this stackoverflow.com/help/how-to-ask
    – rjdown
    Nov 27, 2014 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. Nov 27, 2014 at 12:15

1 Answer 1

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
}
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.