Question

I am trying to echo the youtube video ids of the feed and its not returning anything. I am using following code

      $JSON = file_get_contents("http://gdata.youtube.com/feeds/api/videos?&v=2&q=dance&alt=json");
    $JSON_Data = json_decode($JSON);
foreach($JSON_Data->{'feed'}->{'entry'} as $video):

   echo $video->{'id'};
    endforeach;
Was it helpful?

Solution

Always when i cant find the right elements in a big array, i use print_r() to print it and find it.

This will be your solution:

<?php
$JSON = file_get_contents("http://gdata.youtube.com/feeds/api/videos?&v=2&q=dance&alt=json");
$JSON_Data = json_decode($JSON);
foreach($JSON_Data->feed->entry as $video):
        echo $video->id->{'$t'}."<br/>";
endforeach;
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top