473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

jamwil
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
2 3191
jamwil
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
1,584 Expert 1GB
Thanks for posting the answer!



Dan
Jun 5 '09 #3

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

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
1
by: hwcowan | last post by:
Hello, I have started using SimpleXML and can do most things, but there are a couple of things that I can't seem to figure out. Currently, I can: 1. Open & load an XML file 2. Manually...
3
by: theboss3 | last post by:
Take, for example a typical RSS 2.0 feed (like http://lorelle.wordpress.com/feed/) and tell me how I access the tags like 'content:encoded' and 'wfw:commentRSS' using SimpleXML. I've searched far...
0
Niheel
by: Niheel | last post by:
A few month's back I ran into this site called "Digg". Of course, by now every techie knows about it. At that time, I was just amazed by the way it worked. Right away it got me thinking, these guys...
2
by: mandric | last post by:
Hello, Can someone please enlighten me on how to preserve the <!]> element when parsing an xml file or string with simplexml. I'm using libxml 2.6.16 and php 5.1.4. I tried a few variations,...
2
by: whisher | last post by:
Hi. I'm taking my first steps with xml and SimpleXML functions. xml.php (It could be made dynamically with a mysql result I post this snippet for example ) PHP Code xml.php: <?php $xmlstr...
1
by: Andrew Taylor | last post by:
Hi, I've got an RSS feed I'd like to consume from our Sharepoint server. When I try: $xml = simplexml_load_file($url); I get failed to open stream: HTTP request failed! HTTP/1.1 401...
5
by: Pablo | last post by:
Hello, Does anybody know any tutorial about using PHP5 SimpleXML with forms? I have found some SimpleXML examples, but only modifying node attributes from the php code directly. I would like...
7
by: dimo414 | last post by:
So I'm trying to use SimpleXML to get some attribute information about some nodes in my XML document, but it seems like SimpleXML ignores attributes for elements with no children, For instance:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.