247 people following this project (follow)

linq2twitter_v3_300x90.png

LINQ to Twitter is a 3rd party LINQ Provider for the Twitter micro-blogging service. It uses standard LINQ syntax for queries and includes method calls for changes via the Twitter API.

Example

You can try LINQ to Twitter, even if you don't have a twitter account. The following query returns search results where people are tweeting about LINQ to Twitter:

            var twitterCtx = new TwitterContext();

            var queryResults =
                from search in twitterCtx.Search
                where search.Type == SearchType.Search &&
                      search.Query == "Linq To Twitter"
                select search;

            Search srch = queryResults.Single();

            Console.WriteLine("\nQuery: {0}\n", srch.QueryResult);
            srch.Results.ForEach(entry => 
                Console.WriteLine(
                    "ID: {0, -15}, Source: {1}\nContent: {2}\n",
                    entry.ID, entry.Source, entry.Text));

From a coding experience perspective, the TwitterContext type is analogous to DataContext (LINQ to SQL) or ObjectContext (LINQ to Entities). You use the TwitterContext instance, twitterCtx, to access IQueryable<T> tweet categories. In the example above the Search will give you the ability to search Twitter for tweets meeting some criteria.

Each query category has a Type property for the type of tweets you want to get back. For example, Status tweets can be made for Home, Mentions, or User timelines. Each query category also has an XxxType enum to help you figure out what is available. The example above uses SearchType.Search to perform searches. Another example would be Status queries which might have StatusType.Home as its Type. In the case of Search queries, Search is the only option, but the Type idiom is consistent accross all query categories.

Just like other LINQ providers, you get an IQueryable<T> back from the query. You can see how to materialize the query by invoking the Single operator. For Search results, you receive one Search entity that contains information about the Search query and the Search entity contains a Results property that is a collection of SearchResult entities. On other queries, you would materialize the query with ToList for multiple results. Just like other LINQ providers, LINQ to Twitter does deferred execution, so operators such as ToList and Single or statements such as for and foreach loops will cause the query to execute and make the actual call to Twitter.

For more details on how LINQ to Twitter works, you can either click on the Documentation menu (above) or visit Making API Calls for API specific examples. The downloadable source code also contains copious examples in the LinqToTwitterDemo project.

For the latest news, follow Joe Mayo on Twitter.

NuGet

In addition to being able to download from this site, you can also automatically install LINQ to Twitter into your Visual Studio projects via NuGet; Here's how: A Gentle Introduction to NuGet.

Windows 8 Metro Style Class Library

If you're working with Windows 8, here's a new early beta version of LINQ to Twitter ported as a Windows 8 Metro Style Class Library:

LINQ to Twitter for Windows 8

Samples

LINQ to Twitter Samples contains example code for using LINQ to Twitter with various .NET technologies.

Who is Using LINQ to Twitter?

Services, Sites, and Software that Use LINQ to Twitter

Available Feature Set

See Making API Calls.


Follow Joe on Twitter

Last edited May 9 at 4:40 PM by JoeMayo, version 64