This project has moved and is read-only. For the latest updates, please go here.

Search for all public tweets by certain user

Oct 7, 2010 at 11:40 AM


I am quite new to Tweeter API, so perhaps it is not surprising I can't achieve a simple thing. What I want is simply to collect all tweets by a certain user. The example using REST API is like this:

This will retreive all tweets from al3x.

Now I want to try to do the same with LinqToTwitter. AFAIK I don't need to provide my consumer key/secret when doing such searches. So here's the code:

            var context = new TwitterContext();

            var query = from twit in context.Status
                        where twit.Type == StatusType.Public && twit.User.Name == "al3x"
                        orderby twit.CreatedAt descending
                        select twit;

The code compiles and runs, but I get 0 results. Obviously the combination of parameters is wrong, but I can't figure out what exactly I need to set in order to obtain all tweets from a certain user identified by Username.
Oct 7, 2010 at 2:56 PM


You can use ScreenName, like this:

            var lastN = 11;
            var screenName = "JoeMayo";

            var statusTweets =
                from tweet in twitterCtx.Status
                where tweet.Type == StatusType.User
                      && tweet.ScreenName == screenName
                      && tweet.Count == lastN
                select tweet;

            foreach (var tweet in statusTweets)
                    "(" + tweet.StatusID + ")" +
                    "[" + tweet.User.ID + "]" +
                    tweet.User.Name + ", " +
                    tweet.Text + ", " +

There are dozens of sample programs in the LinqToTwitterDemo project that will show you how to perform various tasks.  Additionally, the documentation, Making API Calls, has most of the APIs, except that I haven't documented some of the most recent.  LINQ to Twitter also supports the Twitter Search API, including advanced searches.  Here's an example that does something similar to the above, except the results are Search rather than Status:

            var queryResults =
                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.PersonFrom == "JoeMayo"
                 select search)

            Console.WriteLine("\nQuery:\n" + queryResults.Title);

            foreach (var entry in queryResults.Entries)
                    "ID: {0}, As of: {1}\nContent: {2}\n",
                    entry.ID, entry.Updated, entry.Content);


Hope that helps,


Oct 7, 2010 at 3:40 PM
Edited Oct 7, 2010 at 4:21 PM


Thank you for the example. It works as long as I look up most recent tweets. If I want to look back in history, things get worse. With twitterCtx.Search I only get 15 most recent entries, and if I extend twitterCtx.Status with the following condition:

                where tweet.Type == StatusType.User
                      && tweet.ScreenName == screenName
                      && tweet.CreatedAt < DateTime.Now.AddDays(-10)

then I don't get anything at all. I.e. it applies date restriction criteria to the most recent tweets (most recent 20) and if I try to search for earlier tweets, I don't get anything at all.

I realize that this is not a problem with Linq provider - I tried to perform search on the Web. Is this a general Twitter search limitation that can't be overcome when using API?

Best regards

P.S. Found that there is 7 days limit on all search results. Then everything gets clear.
Oct 7, 2010 at 9:04 PM

I'm glad you found an answer.  Twitter doesn't return values beyond a certain timeframe and the length of time it goes back depends on the API and possibly other engineering factors on their side.