通过 PHP 使用 Twitter API 的最佳方式是什么? [英] What's the best way to use the Twitter API via PHP?

查看:31
本文介绍了通过 PHP 使用 Twitter API 的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一位客户希望我使用 PHP 内置的自定义解决方案将他们的 Twitter 流添加到他们的网站主页.

A client would like me to add their Twitter stream to their website homepage, using a custom solution built in PHP.

显然,Twitter API 每小时可以进行的调用次数有限,因此我无法在每次有人刷新我客户的主页时自动 ping Twitter.

The Twitter API obviously has a limited number of calls you can make to it per hour, so I can't automatically ping Twitter every time someone refreshes my client's homepage.

客户的网站目前纯 HTML,因此没有数据库可用.因此,我的解决方案必须只需要 PHP 和本地文件系统(例如,保存包含一些数据的本地 XML 文件).

The client's website is purely HTML at the moment and so there is no database available. My solution must therefore only require PHP and the local file system (e.g. saving a local XML file with some data in it).

那么,鉴于这个有限的标准,我访问 Twitter API 的最佳方式是什么(通过 PHP),而不会在几分钟内达到我的 API 调用限制?

So, given this limited criteria, what's the best way for me to access the Twitter API - via PHP - without hitting my API call limit within a few minutes?

推荐答案

这将非常容易,一旦您可以拉下时间线并显示它,然后向其中添加一些基于文件的缓存.

It will be quite easy, once you can pull down a timeline and display it, to then add some file-based-caching to it.

check age of cache
Is it more than 5 mins old?
    fetch the latest information
    regenerate the HTML for output
    save the finished HTML to disk
display the cached pre-prepared HTML

PEAR 的 Cache_Lite 将在缓存层完成您需要的一切.

PEAR's Cache_Lite will do all you need on the caching layer.

这篇关于通过 PHP 使用 Twitter API 的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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