且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

缓存API Twitter调用Twitter Profile Widget

更新时间:2023-09-08 15:08:10

这确实是可能的.从 http://twitter.com/javascripts/widgets/widget.js ,然后更改var profileBase(在第884行附近)以从您网站上的缓存文件而非api.twitter.com中读取.加载新的widjet.js,而不是现在从widgets.twimg.com

This is indeed possible. Grab the uncompressed widget.js from http://twitter.com/javascripts/widgets/widget.js, and change var profileBase (around line 884) to read from the cache file on your site instead of api.twitter.com. Load your new widjet.js instead of the one you're loading now from widgets.twimg.com

对于要读取的实际"twitter缓存"文件-使用cronjob确实是一种方法.当我这样做时,我使用curl来向api.twitter.com发出与当前widget.js完全相同的请求-如果我抓取了widget.js提出的请求的整个URL以及所有GET参数(例如,您可以在Firebug中看到它),将其扔向curl(因此,curl_init($ url)和curl_exec($ url)),然后将curl_exec的输出写入缓存文件.

As for the actual 'twitter cache' file to read from - using a cronjob is indeed one way to do it. When I did this, I used curl to make the exact same request to api.twitter.com that the current widget.js was making - it worked if I grabbed the entire URL of the request made by widget.js, along with all the GET parameters (you can see this in Firebug, for example), threw it to curl (so, curl_init($url) and curl_exec($url) ), and wrote the output of curl_exec into a cache file.