BANGALORE, INDIA: Twitter, the popular social networking platform, is beingused by most companies to promote their products. To post queries in Twitter you don't need to have an ac-count. You can simply use the APIs provided by it or even bet-ter can use a wrapper library to talk. There are wrapper libraries available in your development language. In this article, we shall use .NET and Linq To Twitter (http://www. code-plex. com/LinqToTwitter) library. When you post the following query, Twitter returns a list of public tweets:
Twitter Context context = new Twitter Context(); var tweets = from tweet in context. Status where tweet. Type ==Status Type. Public select tweet; tweets. ToList (). ForEach(tweet => Console.WriteLine( "User Name: {0}, Tweet: {1}, Published: {2}", tweet. User. Name, tweet.Text, tweet .Created At));
Twitter Context is similar to Data Context (LINQ to SQL) or ObjectContext (LINQ to Entities). We use Twitter Context to access I Queryable tweet categories. The example above gives us a collection of IQuery able. Status is an inbuilt class in Linq To Twitter library and reveals a great deal of information about a tweet. Each tweet category has a “Type” property of enumeration for the type of tweets you want to get back. For example, Status tweets can be made for Public, Friend, or User timelines. The example above uses Status Type. Public to get Public Status tweets. Though this query allows me to query twitter for public tweets, I don't have the flexibility to search for things I am interested in. For that we need to write the query in a different way. The following is an example of search query:.
Twitter Context context = new Twitter Context(); List entries = new List(); var search Result = from search in context. Search where search. Type == Search Type. Search && //1. search. Query == "Union Budget 2010" && //2. search. Page Size == 100 && //3. search. Since ID == 1 //4. select search; if (search Result != null) { for each (var search Item in search Result) { if (search Item. Entries != null) { entries. Add Range (search Item. Entries. To List()); } }}
Did you notice the difference? We are not fetching a collection of Status type. We are after Search type that Linq To Twitter provides us. Search class contains a List that we are looking for. This is the collection of tweets that is the result of our query. Let's enumerate what we can achieve through this query:
It is a type of search and Search is the only option in Search Type enumeration.
LinqToTwitter supports advanced search as well those thatare provided by twitter APIs. For more details please visithttp://linqtotwitter.codeplex.com/Thread/View.aspx?ThreadId=79115 and http://search.twitter.com/operators.
You can put the number of records you want to retrieve. Twitter supports retrieving 1500 records at a time. You can play with this number and decide an optimal number ac-cording to your needs.
By giving tweet identities, you can retrieve details of new tweets. On the very first hit, keep the identity as 1 and from there on persist the ID of latest tweet and use that number as Since ID.
Now once you have all the tweets, you can build a Windows service or any other kind of scheduler that fires the above query and retrieves the relevant information periodically.
Get most out of your technology infrastructure investments with Dell
About CIOL | Media Kit | Site Map | Contact Us | Help | Write to us | Jobs@CyberMedia | Privacy Policy
Copyright © CyberMedia India Online Ltd. All rights reserved. Usage of content from web site is subject to Terms and Conditions.