Code Monkey home page Code Monkey logo

linqtotwitter's Introduction

LINQ to Twitter

LINQ to Twitter is an open source 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

The following query returns search results where people are tweeting about LINQ to Twitter:

            var twitterCtx = new TwitterContext(...);

            var searchResponse =
                await
                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.Query == "\"LINQ to Twitter\""
                 select search)
                .SingleOrDefaultAsync();

            if (searchResponse != null && searchResponse.Statuses != null)
                searchResponse.Statuses.ForEach(tweet =>
                    Console.WriteLine(
                        "User: {0}, Tweet: {1}", 
                        tweet.User.ScreenNameResponse,
                        tweet.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 tweet categories. In the example above, the Search will give you the ability to search Twitter for tweets meeting some criteria.

Note: The ellipses in the TwitterContext parameters indicates that you need to provide an authorizer with credentials, which is required. You can visit Securing Your Applications for documentation on authorizers and visit the Download page for working examples.

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 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.

The latest version of LINQ to Twitter supports async. You can see this where the code above await's the query, using the SingleOrDefaultAsync() operator. Commands are async also. e.g. TweetAsync().

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 projects with the Linq2Twitter_ prefix.

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;

For help in getting started with NuGet: A Gentle Introduction to NuGet.

Available Feature Set

See Making API Calls.

For the latest news, follow @JoeMayo on Twitter.

linqtotwitter's People

Contributors

adesugbaa avatar bjcull avatar grennis avatar idisposable avatar joemayo avatar livven avatar timurgilfanov avatar vraposo avatar yazgoo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.