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.... - /////
-
// feed
-
//
-
// LOADS THE RSS FEED FOR
-
// LOOPS THROUGH AND FORMATS/FILTERS POSTS
-
// PULLS THE TIMESTAMP OF THE LATEST UPDATE FROM THE DB
-
// IF THERE ARE NEW POSTS, ADD THEM TO THE DATABASE
-
/////
-
public function feed($feed,$type) {
-
if (isset($feed) && isset($type)) {
-
-
// LOADS THE FEED
-
$xml = simplexml_load_file($feed)
-
or die('Could not load feed');
-
-
// LOOPS THROUGH AND FORMATS/FILTERS
-
foreach ($xml->channel->item as $item) {
-
-
$title = str_replace("\"","",sqlite_escape_string($item->title));
-
$timestamp = strtotime($item->pubDate);
-
$link = sqlite_escape_string($item->link);
-
$description = sqlite_escape_string($item->description);
-
-
// PULLS THE TIMESTAMP OF THE LATEST UPDATE FROM THE DB
-
$qry = $this->db->query("SELECT timestamp FROM updates WHERE type=\"$type\" ORDER BY timestamp DESC LIMIT 1")
-
or die("Could not get latest timestamp");
-
$row = $qry->fetch();
-
$lastUpdated = $row['timestamp'];
-
-
// IF THERE ARE NEW POSTS, ADD THEM TO THE DATABASE
-
if ($timestamp > $lastUpdated || $qry->numRows() == 0) {
-
$qry = $this->db->query("INSERT INTO updates (id, type, timestamp, title, description, link) VALUES (NULL, \"$type\", \"$timestamp\", \"$title\", \"$description\", \"$link\")")
-
or die("Could not Insert post into database");
-
}
-
-
}
-
-
} else {
-
echo "Feed / Type not defined.";
-
}
...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: - <?php
-
ini_set('display_errors',1);
-
error_reporting(E_ALL|E_STRICT);
-
date_default_timezone_set('America/Vancouver');
-
require('lifestream.class.php');
-
$life = new lifestream('stream.db');
-
$life->twitter('jamwil');
-
$life->feed('http://ws.audioscrobbler.com/2.0/user/jamwil/lovedtracks.rss','lastfm');
-
$life->feed('http://digg.com/users/jamwil87/history/diggs.rss','digg');
-
?>
...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
2 3191
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 - ini_set('user_agent','ilovejames/1.0');
Thanks for posting the answer!
Dan
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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:...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| | |