By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

SimpleXML won't load Digg feed, but will load anything else. WTF?

jamwil
P: 13
What's up guys. I'm having some issues... I've created a method as part of my lifestreaming class which takes an rss feed, and puts the data into a database... It's fairly simple... Check it....
Expand|Select|Wrap|Line Numbers
  1. /////
  2. // feed
  3. //
  4. // LOADS THE RSS FEED FOR
  5. // LOOPS THROUGH AND FORMATS/FILTERS POSTS
  6. // PULLS THE TIMESTAMP OF THE LATEST UPDATE FROM THE DB
  7. // IF THERE ARE NEW POSTS, ADD THEM TO THE DATABASE
  8. /////
  9. public function feed($feed,$type) {
  10.     if (isset($feed) && isset($type)) {
  11.  
  12.         // LOADS THE FEED
  13.         $xml = simplexml_load_file($feed)
  14.             or die('Could not load feed');
  15.  
  16.         // LOOPS THROUGH AND FORMATS/FILTERS
  17.         foreach ($xml->channel->item as $item) {
  18.  
  19.             $title = str_replace("\"","",sqlite_escape_string($item->title));
  20.             $timestamp = strtotime($item->pubDate);
  21.             $link = sqlite_escape_string($item->link);
  22.             $description = sqlite_escape_string($item->description);
  23.  
  24.             // PULLS THE TIMESTAMP OF THE LATEST UPDATE FROM THE DB
  25.             $qry = $this->db->query("SELECT timestamp FROM updates WHERE type=\"$type\" ORDER BY timestamp DESC LIMIT 1")
  26.                 or die("Could not get latest timestamp");
  27.             $row = $qry->fetch();
  28.             $lastUpdated = $row['timestamp'];
  29.  
  30.             // IF THERE ARE NEW POSTS, ADD THEM TO THE DATABASE
  31.             if ($timestamp > $lastUpdated || $qry->numRows() == 0) {
  32.                 $qry = $this->db->query("INSERT INTO updates (id, type, timestamp, title, description, link) VALUES (NULL, \"$type\", \"$timestamp\", \"$title\", \"$description\", \"$link\")")
  33.                     or die("Could not Insert post into database");
  34.             }
  35.  
  36.         }
  37.  
  38.     } else {
  39.         echo "Feed / Type not defined.";
  40.     }
...Now I know this function works as I've used it for my last.fm feed as well as a slightly modified version for my twitter rss feed. For some reason though, it won't load my digg rss feed. This doesn't make sense to me... here's the feed.

http://digg.com/users/jamwil87/history/diggs.rss

And here's the implementation:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     ini_set('display_errors',1);
  3.     error_reporting(E_ALL|E_STRICT);
  4.     date_default_timezone_set('America/Vancouver');
  5.     require('lifestream.class.php');
  6.     $life = new lifestream('stream.db');
  7.     $life->twitter('jamwil');
  8.     $life->feed('http://ws.audioscrobbler.com/2.0/user/jamwil/lovedtracks.rss','lastfm');
  9.     $life->feed('http://digg.com/users/jamwil87/history/diggs.rss','digg');
  10. ?>
...This script works perfectly for the twitter, and the last.fm tracks, but fails on the digg feed with this error:
Warning: simplexml_load_file(http://digg.com/users/jamwil87/history/diggs.rss) [function.simplexml-load-file]: failed to open stream: HTTP request failed! in /Applications/MAMP/htdocs/iLoveJames/lifestream.class.php on line 93

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://digg.com/users/jamwil87/history/diggs.rss" in /Applications/MAMP/htdocs/iLoveJames/lifestream.class.php on line 93
Could not load feed
Any ideas? I'm really at a loss here
May 30 '09 #1
Share this Question
Share on Google+
2 Replies


jamwil
P: 13
Figured it out... Digg's api requires any access from a script to have a user agent set... Just added this to the top of the page and she works like a charm
Expand|Select|Wrap|Line Numbers
  1. ini_set('user_agent','ilovejames/1.0');
May 31 '09 #2

dlite922
Expert 100+
P: 1,584
Thanks for posting the answer!



Dan
Jun 5 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.