473,581 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

jamwil
13 New Member
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.simple xml-load-file]: failed to open stream: HTTP request failed! in /Applications/MAMP/htdocs/iLoveJames/lifestream.clas s.php on line 93

Warning: simplexml_load_ file() [function.simple xml-load-file]: I/O warning : failed to load external entity "http://digg.com/users/jamwil87/history/diggs.rss" in /Applications/MAMP/htdocs/iLoveJames/lifestream.clas s.php on line 93
Could not load feed
Any ideas? I'm really at a loss here
May 30 '09 #1
2 3209
jamwil
13 New Member
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 Recognized Expert Top Contributor
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
3042
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 to have an easier time understanding what I do. Therefore this weekend I'm going to spend 3 days just writing comments. Before I do it, I thought...
1
3571
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 parse the XML file 3. Search the XML file using XPath
3
2884
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 and wide for a solution but can't find one. Thank you very much.
0
3508
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 are onto something. Give the power to the users! What I was reading was how this site had given users all the power to moderate and decide what is...
2
14761
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, I found at http://us3.php.net/manual/en/function.simplexml-load-string.php $xml = simplexml_load_string($newsMLString, 'SimpleXMLElement',
2
12361
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 = "<?xml version=\"1.0\" standalone=\"yes\"?>";
1
4207
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 Unauthorized
5
2091
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 to make a simple CMS based on a page with a form containing 2 fields (text description and picture uploader), wich data (the text and the path to...
7
2911
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: <xmlfile> <object foo="bar"> <color mode="rgb">ffddee</color> </object>
0
7876
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7910
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8180
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6563
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1144
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.