在 Rails 站点上显示 Twitter 提要(带有历史记录)的最佳方式 [英] Best way to display a Twitter feed (with history) on a Rails site

查看:39
本文介绍了在 Rails 站点上显示 Twitter 提要(带有历史记录)的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Rails 网站上,我想显示某个 Twitter 提要,并带有分页,以便访问者可以看到以前的推文(只要需要).

On a Rails site, I'd like to display a certain Twitter feed, with pagination so the visitor can see previous tweets (as far back as needed).

我使用 Twitter gem 实现它,使用 Search 方法,它有一个很好的分页方法,但遇到了一个限制,即 Twitter 只会返回过去两周的法规.因此,返回几页后,它将不再获取.

I implemented it using the Twitter gem, using Search method, which has a nice pagination method, but hit a limitation that Twitter will only return the statutes from the last two weeks. So after going back a couple of pages, it won't fetch anymore.

我可以使用带有 max_id 的 user_timeline 方法,然后进行我自己的分页(将查看的最后一个项目的 max_id 传递回控制器以获取下一批).

I could use the user_timeline method, with max_id and then do my own pagination (passing the max_id of the last item viewed back to the controller to fetch the next batch).

或者,我可以有一个 rake 任务,它经常(使用 cron)轮询 Twitter 提要,并将推文存储在数据库中.该站点将从数据库中提供这些服务,而不是查询 Twitter.

Or, I could have a rake task that polls the Twitter feed frequently (with cron), and stores the tweets in the DB. The site would serve those up from the DB instead of querying Twitter at all.

哪种方法是最好的或推荐的方法?我不喜欢将推文存储在数据库中,但这也可以解决查询 Twitter 的延迟问题(尽管我可以使用片段缓存来克服这个问题,但我无法使用它阿贾克斯).

Which would be the best or recommended method? I don't like having to store the Tweets in the DB, but that would also take care of the latency problem of querying Twitter (though I could use fragment caching to overcome that except that I haven't been able to get it working with Ajax).

谢谢你的建议.

推荐答案

我打算将推文存储在数据库中.
因此,即使 twitter 处于离线状态,您也不会遇到一些长时间加载问题.您只需依赖您的数据库,推文就会适当显示.
只有您的后台作业会失败,因为 twitter 不可用.但这并不是真正的问题.

I'd go for storing the tweets in the database.
So even if twitter is offline you won't have some long load problems. You'll just rely on your database and the tweets will be appropriately displayed.
Only your background job will fail because twitter is unavailable. But that's not really a problem.

这篇关于在 Rails 站点上显示 Twitter 提要(带有历史记录)的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆