rssfeedbloggersimplepieblogspot

SimplePie and fetching multiple feeds from blogspot.com


I've been doing a lot of work with SimplePie the last few days and I've noticed it doesn't always treat Blogger feeds the same. If I pass a Blogger feed to SimplePie like this http://davetaylorminiatures.blogspot.com/ or http://sippinonpaintwater.blogspot.com/feeds/posts/default?alt=rss it will display it just fine, but when I pass an array of valid feeds, some from blogspot and some not from blogspot to SimplePie, none of the blogspot items are returned. It doesn't seem to matter if I let it discover the feed or pass in feeds specifying RSS.

If the Blogger blog uses say FeedBurner for its feeds then that will work such as this example http://feeds.feedburner.com/FromTheWarp SimplePie will include items from "From the Warp" a blogspot hosted blog in a merged feed with data from other valid feeds.

I've been doing a lot of merging of feeds and at first I was thinking it was something to do with published date, or caching of feeds locally, but I've blown away my local cache files and run many tests.

One blogspot feed is fine for SimplePie, pass an array of feeds and blogspot feeds seem to be ignored, they don't appear to be cached locally either. Since I know the individual feeds work in feed readers and even in SimplePie News Blocks 2 demo based code, why when I pass them in an array does it not work? Is this a bug in SimplePie or Blogger or am I missing something obvious.

I wrote the following code that test and demonstrates this behavior, it is important that the feeds aren't cached prior to running this I believe.

<?php
require_once('./php/simplepie.inc');

$feed1 = new SimplePie(); // For this test I want four seperate feeds
$feed2 = new SimplePie();
$feed3 = new SimplePie();
$feed4 = new SimplePie();
$feed5 = new SimplePie(); // Fetching the feeds before merging seems to matter with Blogger feeds!

echo "Blogger Feed One http://davetaylorminiatures.blogspot.com/ \n";
echo "---------------------------------------------------------- \n";

$feed1->set_feed_url('http://davetaylorminiatures.blogspot.com/');
$feed1->init();

foreach ($feed1->get_items() as $item)
{
echo $item->get_title();
echo "\n";
}

echo "\n";

echo "Blogger Feed Two http://sippinonpaintwater.blogspot.com/feeds/posts/default?alt=rss \n";
echo "----------------------------------------------------------------------------------- \n";

$feed2->set_feed_url('http://sippinonpaintwater.blogspot.com/feeds/posts/default?alt=rss');
$feed2->init();

foreach ($feed2->get_items() as $item)
{
echo $item->get_title();
echo "\n";
}

echo "\n";

echo "Non-Blogger Feed http://www.witchhunter.net/blog/ \n";
echo "------------------------------------------------- \n";

$feed3->set_feed_url('http://www.witchhunter.net/blog/');
$feed3->init();

foreach ($feed3->get_items() as $item)
{
echo $item->get_title();
echo "\n";
}

echo "\n";

echo "Merged Feeds Test \n";

$feed4->set_feed_url(array('http://davetaylorminiatures.blogspot.com/',
                        'http://sippinonpaintwater.blogspot.com/feeds/posts/default?alt=rss',
                        'http://www.witchhunter.net/blog/'));
$feed4->init();

echo "Merged Feeds Item Titles \n";
echo "------------------------ \n";

foreach ($feed4->get_items() as $item)
{
echo $item->get_title();
echo "\n";
}

echo "\n";

echo "Same Merged Feeds Item and Feed Title \n";
echo "------------------------------------- \n";

foreach ($feed4->get_items() as $item)
{
    echo "\n";
echo $item->get_title();
echo "\n";
echo "From feed: ";
echo $item->get_feed()->get_title();
echo "\n";
}

echo "\n";

echo "Merged Feeds Test, different set of Three Feeds \n";

$feed5->set_feed_url(file('testFeeds.txt'));
$feed5->init();

echo "Merged Feeds Item Titles \n";
echo "------------------------ \n";

foreach ($feed5->get_items() as $item)
{
echo $item->get_title();
echo "\n";
}

echo "\n";

echo "Same Merged Feeds Item and Feed Title \n";
echo "------------------------------------- \n";

foreach ($feed5->get_items() as $item)
{
    echo "\n";
echo $item->get_title();
echo "\n";
echo "From feed: ";
echo $item->get_feed()->get_title();
echo "\n";
}

?>

The contents of testFeeds.txt are:

http://cursedtreasures.blogspot.com/
http://sidneyroundwood.blogspot.com/feeds/posts/default?alt=rss
http://feeds.feedburner.com/ChestOfColors

I wanted to see if putting the feeds in an external file mattered, as that is how I prefer to fetch multiple feeds. The output from $feed5 is where things go weird, it will return only results from Chest of Colors the first time it is run. Once feeds start getting cached or if you fetch the feeds individually first, it seems to matter. This is the out put of $feed5 just now:

Merged Feeds Test, different set of Three Feeds

Merged Feeds Item Titles

Brushes review: Winsor Newton series 7 vs Rosemary and Co NMM gold made fast and easy 5th Chest of Colors Miniature Exchange Summary Warploque Miniatures: Jebzakkah B’Ork – Review Miniature of the month: January 2012 Between the Lines – Episode 5 Golden Demons 2011: Clash of Slayer Sword winners Games Workshop: FineCast Jabberslythe – Review Miniature of the month: December 2011 Romeo Models: Jean Bart – Review

Same Merged Feeds Item and Feed Title

Brushes review: Winsor Newton series 7 vs Rosemary and Co From feed: Chest of Colors - All about miniature painting

NMM gold made fast and easy From feed: Chest of Colors - All about miniature painting

5th Chest of Colors Miniature Exchange Summary From feed: Chest of Colors - All about miniature painting

Warploque Miniatures: Jebzakkah B’Ork – Review From feed: Chest of Colors - All about miniature painting

Miniature of the month: January 2012 From feed: Chest of Colors - All about miniature painting

Between the Lines – Episode 5 From feed: Chest of Colors - All about miniature painting

Golden Demons 2011: Clash of Slayer Sword winners From feed: Chest of Colors - All about miniature painting

Games Workshop: FineCast Jabberslythe – Review From feed: Chest of Colors - All about miniature painting

Miniature of the month: December 2011 From feed: Chest of Colors - All about miniature painting

Romeo Models: Jean Bart – Review From feed: Chest of Colors - All about miniature painting

Any ideas on what is happening besides the obvious that it seems to matter whether you've already fetched and cached a Blogger feed individually before trying to merge it? The test script is up and running here


Solution

  • I'm using SimplePie 1.3 (latest version), and doing the code this way and it seems to work for me:

    $feed = new SimplePie();
    
    $feed_ary = array();
    $feed_ary[] = 'http://simplepie.org/blog/feed/';
    $feed_ary[] = 'http://hurtnordic.blogspot.com/feeds/posts/default?alt=rss';
    $feed_ary[] = 'http://rochesternordicracing.blogspot.com/feeds/posts/default?alt=rss';
    
    // Set the feed(s) to process. Blogspot format: http://blogname.blogspot.com/feeds/posts/default?alt=rss
    $feed->set_feed_url($feed_ary);
    
    // limit the number of items
    $feed->set_item_limit($max_items_per_feed);
    
    // Run SimplePie.
    $success = $feed->init();
    
    $feed->handle_content_type();
    

    It merges the feeds and sorts them by date since all the ones listed have the date field. Note that the format for blogspot feeds is: Blogspot format: http://blogname.blogspot.com/feeds/posts/default?alt=rss, which you have in some but not all of your feed urls.