This loads up a Twitter feed and displays the last tweet.
Is there a way to include an开发者_如何转开发d retrieve all the retweets in this function?
$(document).ready(function() {
var url = "http://twitter.com/status/user_timeline/mytwittername.json?count=3&callback=?";
var lastClass = "";
$.getJSON(url,
function(data){
$.each(data, function(i, item) {
// check for last tweet
if (i == (data.length - 1)) {
lastClass = "class='last'"
}
$("#twitter-content ul").append("<li " + lastClass + ">" + item.text.linkify().atify() + " <span class='created_at'>[" + relative_time(item.created_at) + " via " + item.source + "]</span></li>");
});
});
$("#sidebar ul li:last-child").addClass("last");
});
Modify the url
variable in your code to be the following:
http://api.twitter.com/1/statuses/user_timeline/mytwittername.json?count=3&include_rts=1&callback=?
The magic is in the include_rts=1
parameter which will cause retweets by the target user to be included in their timeline.
The statuses/user_timeline method does not require authentication, however if you do auth, you'll get an extra 200 API calls per hour. Note that the twitter.com
REST methods are no longer supported, so be sure to use the versioned API methods when interacting with Twitter.
Take a look here:
https://dev.twitter.com/docs/api/1/get/statuses/retweets/:id
In your loop if you had the id of the original tweet then you could probably get the retweet as well.
I haven't tried it, but this is what I found.
Good Luck!
精彩评论