使用jQuery的Twitter feed [英] Twitter feed using jQuery
问题描述
我正在尝试通过使用jQuery解析twitter提供的JSON文件来制作一个显示5条tweet的twitter feed.我在这里做了jsFiddle .
I'm trying to make a twitter feed that shows 5 tweets by using jQuery to parse a JSON file, provided by twitter. I've made jsFiddle over here.
$(document).ready(function () {
var k = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=Twitter&include_rts=1&count=5";
$.getJSON(k, function (data) {
$.each(data, function (i, item) {
$("#tweetFeed").append("<div class='tweetCloud'><div id='tweetArrow'></div><div id='tweetText'>" + item.text.linkify() + "</div></div>");
});
});
});
tweet必须由jQuery代码以以下方式输出:
The tweets must outputted by the jQuery code in the following way:
<div class="tweetCloud">
<div id="tweetArrow"></div>
<div id="tweetText">tweet text</div>
</div>
只需要使用推文的文本.
Only the text of the tweets need to be used.
正如您在jsFiddle中看到的那样,没有显示任何鸣叫,而且我也不知道为什么.我在jQuery方面没有太多经验,而在JSON方面几乎没有经验,所以我希望有人能给出清楚的解释,为什么这行不通.
As you can see in the jsFiddle, no tweets are displayed, and I don't know why. I don't have much experience with jQuery, and practically none with JSON, so I hope someone can give a clear explanation why this doesn't work.
谢谢.
推荐答案
您的代码未使用JSONP,因此受到跨域限制的拒绝.我已经修改了请求,现在可以使用了.这是代码,这是小提琴
Your code wasn't using JSONP and therefore being denied by cross domain restrictions. I've modified the request and it works now. Here's the code and here's the fiddle
$(document).ready(function () {
var k = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=Twitter&include_rts=1&count=5&jsoncallback=";
$.ajax({
dataType: 'jsonp',
url: k,
success: function (data) {
$.each(data, function (i, item) {
$("#tweetFeed").append("<div class='tweetCloud'><div id='tweetArrow'></div><div id='tweetText'>" + item.text + "</div></div>");
})
}
});
});
您在CSS中的imgur链接为404,因此我将其注释掉.另外,linkify()
也不是方法.也许您忘了链接其他库.最后,您指向droid字体的链接未正确嵌入jsfiddle中.
Your imgur link in the CSS was 404'ing so I commented that out. Also, linkify()
is not a method. Perhaps you forgot to link some additional library. Lastly, your link to the droid font was improperly embedded on jsfiddle.
这篇关于使用jQuery的Twitter feed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!