YouTube XML Feed Error

Grant1177

New Member
I've got a page on a website that's pulling my favorites feed from YouTube and embedding them into site.The problem is it's working 80% of the time, but the other 20% of the time i'm getting errors on the page - nothing in the code is changing to cause this, so i'm wondering what might be causing this, or if there's a better way to do what i'm doing...The Error I'm gettings is a 403 Forbidden when retrieving the XML feed... here's what it looks like (note: the line numbers won't match exactly, because i've simplified the code sample below.The XML feed in question is here: \[code\]https://gdata.youtube.com/feeds/api/users/umarchives/favorites\[/code\]\[code\]Warning: simplexml_load_file(https://gdata.youtube.com/feeds/api/users/umarchives/favorites) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /mnt/stor3-wc2-dfw1/web/content/videos.php on line 42Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "https://gdata.youtube.com/feeds/api/users/umarchives/favorites" in /mnt/stor3-wc2-dfw1/web/content/videos.php on line 42Warning: Invalid argument supplied for foreach() in /mnt/stor3-wc2-dfw1/web/content/videos.php on line 47\[/code\]Here's the code i'm using:\[code\]<?php // set feed URL $YouTubeUsername = "umarchives"; $feedURL = "https://gdata.youtube.com/feeds/api/users/".$YouTubeUsername."/favorites"; // read feed into SimpleXML object $sxml = simplexml_load_file($feedURL); // iterate over entries in feed foreach ($sxml->entry as $entry) { // get nodes in media: namespace for media information $media = $entry->children('http://search.yahoo.com/mrss/'); $attrs = $media->group->content->attributes(); $videoURL = $attrs['url']; $videoURL = preg_replace('/\?.*/', '', $videoURL); $videoURL = str_replace("/v/","/embed/",$videoURL); $videoTitle = $media->group->title; echo "<iframe class='youtube-player' width='300' height='225' src='http://stackoverflow.com/questions/7093943/$videoURL'></iframe>\n"; echo "<br>\n"; } ?>\[/code\]
 
Top