LINQ to Twitter, v0.90

Rating: No reviews yet
Downloads: 115
Released: May 18, 2009
Updated: May 18, 2009 by JoeMayo
Dev status: Beta Help Icon

Recommended Download

Source Code LINQ to Twitter Source Code
source code, 807K, uploaded May 18, 2009 - 115 downloads

Release Notes

LINQ to Twitter is a Language Integrated Query (LINQ) provider for the Twitter micro-blogging service.

The primary features of this release include Trends and OAuth. You can now query Twitter trends; including current, daily, and weekly trends.

Here's an example of how you can perform a trend search:

            var trends =
                from trend in twitterCtx.Trends
                where trend.Type == TrendType.Trend
                select trend;

                trend => Console.WriteLine(
                    "Name: {0}, Query: {1}, Date: {2}",
                    trend.Name, trend.Query, trend.AsOf));
Another important feature is the ability to authenticate a user via OAuth, an industry standard adopted by companies such as Google, MySpace, and Yahoo; as well as Twitter. OAuth allows an application to communicate with a service provider without the user needing to give the application their credentials. For LINQ to Twitter, that means you can write your own Twitter application or utility without forcing users to give you their Twitter credentials.

Here's an example of how OAuth works with LINQ to Twitter:

            Console.Write("Consumer Key: ");
            twitterCtx.ConsumerKey = Console.ReadLine();
            Console.Write("Consumer Secret: ");
            twitterCtx.ConsumerSecret = Console.ReadLine();

            string link = twitterCtx.GetAuthorizationPageLink();

            Console.WriteLine("Authorization Page Link: {0}\n", link);
            Console.WriteLine("Next, you'll need to tell Twitter to authorize access. This program will not have access to your credentials, which is the benefit of OAuth.  Once you log into Twitter and give this program permission, come back to this console and press Enter to complete the authorization sequence.\n\nPress Enter now to continue.");

            // launches browser so you can log in and give permissions

            Console.WriteLine("\nYou should see your browser navigate to Twitter, saying that your application wants to access your Twitter account. Once you've authorized this program, return to this console and press any key to execute the LINQ to Twitter code.");
            var uri = new Uri(link);
            NameValueCollection urlParams = HttpUtility.ParseQueryString(uri.Query);
            string oAuthToken = urlParams["oauth_token"];


            if (twitterCtx.AuthorizedViaOAuth)
                var status = twitterCtx.UpdateStatus("I used LINQ to Twitter with OAuth: " + DateTime.Now.ToString());

                    "Friend: {0}\nTweet: {1}\n",
If you visit the OAuth site or search for information on the Web, you'll learn that the sequence of events is somewhat like this:

1. Get a request token from the service provider, stating your desire to use the service, which happens during the call to GetAuthorizationPageLink().
2. Redirect the user to the Twitter authorization page, whose address was returned by the call to GetAuthorizationPageLink(), as shown in Process.Start().
3. Obtain an access token, saved by the TwitterContext so you can use LINQ to Twitter on the user's Twitter account.
4. Check AuthorizedViaOAuth to make sure access was granted. i.e. what if the user chose not to authorize your application.

Note: LINQ to Twitter still supports basic authentication.


Reviews for this release

No reviews yet for this release.