缓存API Twitter调用Twitter Profile Widget [英] Caching API Twitter calls for Twitter Profile Widget

查看:169
本文介绍了缓存API Twitter调用Twitter Profile Widget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在本地开发一个网站, 该网站对两个独立的Twitter提要两次使用Twitter Profile Widget.

I'm developing a site locally, the site uses the Twitter Profile Widget twice, for two separate twitter feeds.

我已经几次遇到了限速(每小时150个呼叫/小时),并且我一直在寻找解决方法.

I've come up against the Rate Limit (150 calls / per hour) a few times now and i've been looking at ways to manage this.

我发现的一种技术是使用Cron Jobs调用一个PHP文件,该文件每10分钟缓存一次Twitter API调用,将其保存到服务器上的txt文件中,然后使用JQuery进行解析.步骤2,3,5 .. http://net.tutsplus.com/教程/php/how-to-to-create-an-advanced-twitter-widget/

One technique i've found uses Cron Jobs to call a PHP file that caches the Twitter API call every 10 minutes, saving it to a txt file on the server and parsing it using JQuery. Steps 2,3,5.. http://net.tutsplus.com/tutorials/php/how-to-create-an-advanced-twitter-widget/

我的问题是..然后我如何将JSON内容解析到我的Twitter Profile Widget中?

My question is.. how would i then parse the JSON contents into my Twitter Profile Widget?

我怀疑这可能无法实现.

I suspect this might not be possible..

下面是用于显示Twitter提要的标准Twitter Profile Widget代码.

below is the standard Twitter Profile Widget code used to display the twitter feeds.

<script charset="utf-8" src="http://widgets.twimg.com/j/2/widget.js"></script>
            <script>
                new TWTR.Widget({version: 2, type: 'faves', rpp: 10, interval: 30000, title: ' ',subject: ' ', width: 210, height: 330,
                  theme: {
                    shell: {
                      background: ' ',
                      color: '#ffffff'
                    },
                    tweets: {
                      background: '#ffffff',
                      color: '#444444',
                      links: '#53cdc7'
                    }
                  },
                  features: {
                    scrollbar: true,
                    loop: false,
                    live: true,
                    behavior: 'all'
                  }
                }).render().setUser('diariesdownundr').start();

                new TWTR.Widget({version: 2,type: 'faves',rpp: 10,interval: 30000,title: ' ',subject: ' ',width: 210,height: 330,
                  theme: {
                    shell: {
                      background: ' ',
                      color: '#ffffff'
                    },
                    tweets: {
                      background: '#ffffff',
                      color: '#444444',
                      links: '#53cdc7'
                    }
                  },
                  features: {
                    scrollbar: true,
                    loop: false,
                    live: true,
                    behavior: 'all'
                  }
                }).render().setUser('diaries1').start();
            </script>

推荐答案

这确实是可能的.从 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.

这篇关于缓存API Twitter调用Twitter Profile Widget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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