SimplePie 不解析 flickr feed
我正在尝试使用 SimplePie 拉取组池 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();
然后我使用典型的 SimplePie php 调用来循环访问 feed 项目。但是,什么也没有返回。 HTML 存在,但提要元素未插入。
当我尝试使用 flickr feed 标签时,例如:
$feed->set_feed_url('http://api.flickr.com/services/feeds/photos_public.gne?tags=architecture,building&lang=en-us&format=rss_200');
我从公共照片 feed 中获取照片列表,但不考虑标签。
有什么想法吗?我唯一能想到的是我需要一个 API 密钥,但 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
“replace_invalid_with_pct_encoding”的目的是转义查询字符串中的所有无效字符。
因此,仅仅删除它可能不是最安全的选择。从那时起,通过 rss 条目传入的链接中的无效字符也不再被转义。这可能不是您想要的。
您遇到的问题不是由问号引起的,而是由“=”和“&”的存在引起的您的网址中的字符。
我遇到了同样的问题,并将这两个字符添加为“有效”字符,如下所示:
$this->query = $this->replace_invalid_with_pct_encoding($query,
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$\'()*+,;:@/?=&');
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-._~!$\'()*+,;:@/?=&');
我能够找到答案——感谢 ceejayoz 帮助我找出要搜索的内容。
在此处找到了答案。
在 simplepie.inc 中,大约第 12146 行,您应该看到以下函数:
将其更改为:
我不太确定这会如何影响代码中的其他内容,但它似乎可以拉入查询的项目。
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:
Change it to this:
I'm not really sure how this affects other things in the code, but it seems to work to pull in the queried items.
将
"&="
添加到set_query
函数就像一个魅力! (谢谢帕特里斯)我对设置为空感到不舒服,因为这个包的安全部分超出了我的理解范围。我花了好几个小时绞尽脑汁,试图从我的 phpBB 论坛获取提要来链接到姊妹网站。
get_links
是这个难题的最后一块。对我有用。Adding that
"&="
to theset_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.这对于我正在编写的 Flickr / ZenPhoto / Picasa Web RSS 脚本很有用,该脚本可以根据提要创建小方形拇指。
我想稍微完善一下,并准备代码供其他人使用,而不仅仅是我自己的使用,但是 此处 就是这样。
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.
我遇到了同样的问题,解决方案是确保您获取的是小组图像池的 RSS 提要,而不是小组讨论的 RSS 提要,然后缩略图就可以随时使用。
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.