SimplePie not parsing flickr feed
I am trying to use SimplePie to pull a group开发者_开发知识库 pool flickr feed:
$feed = new SimplePie();
$feed->set_feed_url('http://api.flickr.com/services/feeds/groups_pool.gne?id=25938750@N00&lang=en-us&format=rss_200');
$feed->init();
$feed->handle_content_type();
Then I use typical SimplePie php calls to loop through the feed items. However, nothing is returned. The HTML is there, but the feed elements aren't inserted.
When I try to use a flickr feed of tags, like:
$feed->set_feed_url('http://api.flickr.com/services/feeds/photos_public.gne?tags=architecture,building&lang=en-us&format=rss_200');
I get back a list of photos from the public photo feed, but the tags aren't taken into account.
Any ideas? The only thing I can think of is I need an API key, but there is nothing on the flickr website that indicates a key is needed for feed calls. Plus, I can open both types of feeds in my browser and get the feed I am looking for.
The purpose of 'replace_invalid_with_pct_encoding' is to escape all invalid characters in a query string.
so just removing it may not be the safest option. Since then invalid characters in links that are coming in via the rss entries are not escaped anymore either. And that's probably not what you want.
The problem you encounter is not caused by the questionmark, rather it is caused by the presence of '=' and '&' characters in your url.
I had the same issue and added these two characters as 'valid' characters as follows:
$this->query = $this->replace_invalid_with_pct_encoding($query, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$\'()*+,;:@/?=&');
I was able to find an answer -- thanks to ceejayoz for helping me figure out what to search for.
Found the answer here.
In simplepie.inc, around line 12146, you should see the following function:
function set_query($query)
{
if ($query === null || $query === '')
{
$this->query = null;
}
else
{
$this->query = $this->replace_invalid_with_pct_encoding($query,
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$\'()*+,;:@/?');
}
$this->valid[__FUNCTION__] = true;
return true;
}
Change it to this:
function set_query($query)
{
if ($query === null || $query === '')
{
$this->query = null;
}
else
{
$this->query = $query;
}
$this->valid[__FUNCTION__] = true;
return true;
}
I'm not really sure how this affects other things in the code, but it seems to work to pull in the queried items.
Adding that "&="
to the set_query
function worked like a charm! (Thanks Patrice)
I was uncomfortable setting to null, since security parts of this package are way above my head. Was banging my head for hours, trying to get feeds from my phpBB forums to link to sister site.
get_links
was last piece of the puzzle. Works for me.
This was useful for a Flickr / ZenPhoto / Picasa Web RSS script I am writing that creates little square thumbs from feeds.
I want to polish it a little, and prepare the code for others' use instead of just my own, but here it is as it stands.
I had the same issue and the solution was to make sure you're getting the RSS feed for the Group's image pool, not the RSS feed for the Group's discussion, then the thumbnails were readily available.
精彩评论