I have a loop going through the youtube feed and it works fine, but by the end it fails with an error:
Warning: main() [function.main]: Node no longer exists in ../youtubereader.php on line 8 Warning: main() [function.main]: Node no longer exists in .../youtubereader.php on line 8 Fatal error: Call to a member function attributes() on a non-object in .../youtubereader.php on line 9
My code is:
<?php error_reporting(E_ALL); $feedURL = 'http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?max-results=50'; $sxml = simplexml_load_file($feedURL); $i=0; foreach ($sxml->entry as $entry) { $media = $entry->children('media', true); $watch = (string)$media->group->player->attributes()->url; $thumbnail = (string)$media->group->thumbnail[0]->attributes()->url; ?> <div class="videoitem"> <div class="videothumb"><a href="<?php echo $watch; ?>" class="watchvideo"><img src="<?php echo $thumbnail;?>" alt="<?php echo $media->group->title; ?>" /></a></div> <div class="videotitle"> <h3><a href="<?php echo $watch; ?>" class="watchvideo"><?php echo $media->group->title; ?></a></h3> <p><?php echo $media->group->description; ?></p> </div> </div> <?php $i++; if($i==3) { echo '<div class="clear small_v_margin"></div>'; $i=0; } } ?>
My xml returns from youtube perfectly, and there are certain results, than where it breaks down, any ideas why it will do it?
Edit: Tested in place using wamp and it works great. Not yet on the server. Live, thumbnails after element 24 no thumbnails.
php youtube-api simplexml
Ashley
source share