1

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

Muskie
  • 577
  • 3
  • 21
  • I still don't know why, but I wrote a simpler test case [link](http://news.muschamp.ca/bloggerTest.php) It required five instances of SimplePie or maybe not, I used four feeds from Blogger, two feeds from elsewhere. Blowing away cached data matters. If you fetch the feeds individually and display the titles, then merge it works as expected, but if you don't fetch the feeds individually and consider a second set of three feeds, two from Blogger, one not, only items not from Blogger appear in the merged results. Blowing away the cache matters. I'll try to add my test code above. – Muskie Mar 09 '12 at 16:53
  • Calling $item->get_feed()->get_title() may force the fetching of the Blogger feeds, but in the fifth test case even that wasn't enough. That is why I loop through the merged feeds $feed4 and $feed5 twice. This behavior was really annoying me, it is good I could document it with a test case, but it is bad for my current project I'm using SimplePie for... – Muskie Mar 09 '12 at 17:11
  • Could blogspot be throttling me? Did it work at first in the morning because I wasn't throttled yet for the day? These feeds I subscribe to in my news reader (NewsFire) but it probably pulls data from a different domain/agent... – Muskie Mar 09 '12 at 21:43
  • I'm pretty sure having tried many setting combinations, something goes wrong in init(), but I've also discovered the problem isn't just blogspot feeds, I've tried using auto discovery, but I also discovered that most blogspot blogs like http://corbaniaprime.blogspot.com/ have Atom feed that uses Feedburner such as http://feeds.feedburner.com/CorbaniaPrime blowing away the cache and rerunning using the Feedburner feed works... But I have to manually check and change every feed. Ideas? – Muskie Mar 10 '12 at 18:21
  • I've come up with something of a work around, I still think there is a problem possibly in init() with SimplePie and blogspot feeds. Basically I fetch a random feed and display it as part of news.muschamp.ca then I merge a bunch of feeds together with some other PHP and SimplePie and display the merged feed. As the individual feeds get cached the merged feed gradually gets bigger. I still wish this problem did not manifest itself when merging blogspot feeds with SimplePie as I demonstrated above... – Muskie Mar 12 '12 at 22:37
  • I'll have to blow away the caches to be sure, but this behaviour may no longer be happening, but test script is still online, but I also fetch and cache these feeds with other more 'production' code. – Muskie Jul 11 '12 at 16:36

1 Answers1

1

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.

Revent
  • 2,091
  • 2
  • 18
  • 33
  • Thanks for trying, but I gave up on this and coded a work around. I'll accept your answer, maybe whatever bug is now fixed in SimplePie itself. – Muskie Apr 19 '13 at 23:45
  • Thank you for accepting my answer, at least you have a workaround. If you do get more information on this, please post it for posterity. – Revent Apr 20 '13 at 00:19