2011-09-21 303 views
2
<script src="http://widgets.twimg.com/j/2/widget.js"></script> 
<script> 
new TWTR.Widget({ 
    version: 2, 
    type: 'profile', 
    rpp: 20, 
    interval: 4000, 
    width: 'auto', 
    height: 300, 
    theme: { 
    shell: { 
     background: '#e1e1e1', 
     color: '#0e89c7' 
    }, 
    tweets: { 
     background: '#ffffff', 
     color: '#444444', 
     links: '#6c8711' 
    } 
    }, 
    features: { 
    scrollbar: true, 
    loop: false, 
    live: true, 
    hashtags: true, 
    timestamp: true, 
    avatars: false, 
    behavior: 'all' 
    } 
}).render().setUser('xxxxxxxxxxx').start(); 
</script> 

我不知道为什么,但有时它不呈现。Twitter个人资料部件有时无法呈现

有人可以告诉我为什么?

谢谢。

+0

难道是widgets.twimg.com有时是缓慢或下降?你是否在同一页面上调用其他外部脚本可能会减慢速度? –

回答

1

很可能Twitter本身可能会关闭,Twitter的API可能会关闭,您的API限制(请求数量)已达到,或者twimg.com关闭(因为此帖子twimg.com已关闭为了我)。

脚本的第一件事是从twimg.com加载js。你可以尝试在本地保存该文件,并从服务器运行它而不是twimg ...有可能它仍然有效,并且它不会要求你的站点每次都打twimg.com(然后,我不知道这个特定的部件)。

虽然小部件方法非常简单,但Twitter有一个非常简单的API,您可以与自己进行交互,如果您想减少等式中的服务器数量。例如,这将让你一堆JSON数据的用户:

http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=一些用户名

要“正确地”做到这一点,你需要某种形式的缓存系统的到位,使你每次有人访问您的网站时都不要经常ping Twitter。为此,您必须使用一些服务器端代码(如PHP)来弄脏。虽然这不是很糟糕,并且有很多tutorials on how to do it

祝你好运!