Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

restful service rss


Reply


4 Posts   3727 Views

Avatar
superautomatic

Community Member, 53 Posts

10 June 2008 at 9:33pm

Edited: 10/06/2008 9:47pm

Hi, I'm trying to import and display an external rss-feed, as in the example code on "How to use RestfulService to easily embed an RSS feed" (http://doc.silverstripe.com/doku.php?id=restfulservice)

It works well if I use the rss feed in the example, but if I use another rss (for example http://www.euro2008.uefa.com/rss/index.xml), it returns nothing at all. Why is this?

Avatar
Willr

Forum Moderator, 5513 Posts

11 June 2008 at 1:58pm

The blog modules RSS Feed widget uses SimplePie. I dont know how it differs from RestFulService it terms of what you actually want to do but that uses something like

http://pastie.org/212736

Avatar
Reflektera

49 Posts

1 December 2008 at 8:30am

I have the same problem as superautomatic. Got it working as described in [url=http://doc.silverstripe.com/doku.php?id=restfulservice#how_to_use_restfulservice_to_easily_embed_an_rss_feed]the documentation[/url], with help from the comments. But it only works with that feed, none else.

I can't seem to get the http://mypage/PageComment/rss/ feed working either. It says that Xml- or textdeclaration not in beginning of entity. Any clues on that?

Besides that there is a typo in RestfulService.php, in line 134. $respnoseBody should be $responseBody I suppose.

Avatar
jam13

121 Posts

1 December 2008 at 9:35pm

With 2.3 coming up I decided to use the RestfulService.php from the 2.3 branch instead of the current stable one, and as it is pretty self contained it seems to work fine on 2.2.3.

The problem I had was with the difference in format between RSS feeds of different versions: RSS 1.0 places the <item> tags outside the <channel>, while RSS 2.0 places them outside. The end result of this is that you need to call getValues slightly differently, here's a snippet of code that I wrote for a recent site:

function Items($limit = 3) {
if(!$this->Link) return 0;
$feed = new RestfulService($this->Link);
$feedXML = $feed->request()->getBody();

// Extract items from feed
if($this->Type == 'RSS2') {
$result = $feed->getValues($feedXML, 'channel', 'item');
} elseif($this->Type == 'RSS1') {
$result = $feed->getValues($feedXML, 'item');
}

// Return items up to limit
return $result->getRange(0,$limit);
}

Hope that helps.

BTW I've posted a patch to Trac that re-enables the response caching as I couldn't live without it for this site. Not sure whether it's good enough for inclusion in trunk though.