0

Hi everyone,

I'm developing a music website and got stuck on this problem. Whenever a user submits a playlist from youtube, i fetch for video thumbnails and list them for the user. Here's the code:

<? $site = 'youtube'; }
$plID = str_replace("http://www.youtube.com/playlist?list=", "", $url);
$xmlLink = "http://gdata.youtube.com/feeds/api/playlists/" . $plID;
$xml = simplexml_load_file($xmlLink);
$videos = array();
foreach ($xml as $video) {
      $vid = array();
      $vid['title'] = $video->title;
      $media = $video->children('http://search.yahoo.com/mrss/');
      $yt = $media->group->children('http://gdata.youtube.com/schemas/2007');
      $attrs = $media->group->thumbnail[0]->attributes();
      $vid['thumbnail'] = $attrs['url'];
      $videos[]=$vid;

}?>

It used to work fine, however now im getting the following error:

Fatal error: Call to a member function attributes() on a non-object in...

Any ideas?

3
Contributors
4
Replies
23
Views
4 Years
Discussion Span
Last Post by EdvinasSelskas
0

I no longer get an error when i replace $xml to $xml->videos in the foreach loop call. No images are being show though when i use this call:

`

<?
foreach($videos as $vid)
{
?>
<img src="<? echo $vid['thumbnail'][0] ?>" width="150" />
<?
}
?>

`

0

What is says is that $media->group->thumbnail[0] is not an object. Maybe you could find out why? I haven't worked with simplexml for a while, but maybe it doesn't give all the properties it contains the possibility to use the attributes() function? Just some thoughts ^^.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.