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?

Recommended Answers

All 4 Replies

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" />
<?
}
?>

`

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 is the correct way

foreach ($xml->entry as $video)

thanks pixelsoul!

That works like a charm :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.