Am using jQuery to retrieve tweets in .json. One part of my application requires old tweets, and twitter search returns tweets only for last 6 days. This old tweets have to contain certain hashtag.
I know that user_timeline API method can return 3200 tweets, but i cant understand how to get 3200 tweets, loop through them and find tweets i need.
Here is what i have for now:
function TwitterAPI(){}
TwitterAPI.Statuses = function Statuses(){}
TwitterAPI.Statuses.hashed = function(username, hashtag, count, to, callback){
requestURL = "http://search.twitter.com/search.json?q=%23" + hashtag + "&rpp=" + count + "&from=" + username + "&to=" + to + "&callback=?";
//requestURL = "http://otter.topsy.com/search.json?q=from:" + username + "+" + hashtag + "&perpage=1"
$.getJSON(requestURL, callback);
}
var user_info = ["name", "birthday", "hobby", "homepage"];
$("#info ul li.userinfo").append('<img src="images/lilspinner.gif" />');
$.each(user_info, function() {
var hashtag = this;
TwitterAPI.Statuses.hashed("<%= @profile.name %>", hashtag, 1, "twisnt", function(json, status){
var content = "";
$.each(json.results, function(i, info){
text = info.text.replace( /(\#)\w+\b/,"").replace( /(\@)\w+\b/,"");
if (hashtag == "homepage") {
content = "<a style='display:none' href='"+text+"'>"+text+"</a>";
}
else {
content = "<span style='display:none'>"+text+"</span>";
}
});
$("li#" + hashtag).append(content);
$("li#" + hashtag + " img").remove();
$("li#" + hashtag + " *").fadeIn("slow");
})
});
It does everything i need, but only when needed messages where tweeted in last 6 days,
According to the twitter API you can only get 100 results at a time. Use the rpp search item to request 100 and start on page 1. Then you can loop through pages getting 100 items at a time. Do this 15 times to get 1500 items. The reason for this is twitter only allows you to get the last 15 pages for a max of 1500 items.
Example:
Source:
Twitter API