Click here to Skip to main content
15,123,757 members
Articles / Programming Languages / C#
Posted 26 Jun 2009

Tagged as


23 bookmarked

Zeta Twitter

Rate me:
Please Sign up or sign in to vote.
3.88/5 (31 votes)
5 Nov 2009CPOL5 min read
Auto Follow Keywords On Twitter

Image 1


In this article I will introduce you a small console application written in C# and .NET 3.5 that enables you to automatically follow Twitter users based on keywords they use in their tweets.

If you don't know Twitter, you may look at their website or read the Wikipedia article about Twitter.


The motivation for developing this tool was to enable some of our company's Twitter accounts to automatically follow other Twitter users based on the keywords they post.

E.g. we maintain a Twitter account for our CMS Zeta Producer Desktop. Now I wanted to do a search for "cms" on Twitter and follow all users (or the first n ones) that were displayed in the search result.

Even though a similar service exists with Twollow, they charge for their services. Since I wanted a free version (although I do have way less features than they have implemented), I started developing Zeta Twitter.

Technical implementation

The application is a .NET 3.5 console application that is intended to be used as a scheduled task in the Windows Task Scheduler. You would e.g. configure the task to run every 30 minutes.

Image 2
Example screenshot of the output of the ZetaTwitter.exe console application.

I am using the free library tweet# to communicate with the Twitter API.

You can add multiple Twitter accounts and for each account multiple keywords to check. The whole configuration is done within a separate configuration file called "ZetaTwitterConfiguration.xml". This file must be stored in the same folder as the executable "ZetaTwitter.exe".

Image 3
Example configuration file.

Currently all attributes are mandatory. Adjust the file in the downloaded archive with the XML/text editor of your choice.

Internal function

Since being nicely asked to explain my code a little bit, this chapter outlines the highlights. Again the warning that none of the code is rocket science.


The configuration is being stored in an XML file (as stated above) and being read into two classes by simple XmlDocument method calls. I do read it manually, not with any XML to class mapping.

The classes are:

  • Configuration - The root class which has an array of Account objects each for each <account> node in the configuration file.
  • Account - The representation of one account. Has an array of string objects for the keywords specified in the configuration file.


The processing is done the Program class. Using the IsAlreadyRunning property (which is implemented with a mutex) to quit itself if it is already running. So it is a single-instance console application.

Reason for that is that depending on the configuration file size, one run may take rather long and I wanted to avoid that the Windows Task Scheduler fire multiple instances. Twitter only allows a limited number of requests per IP address per day, so you better play nice here.

The Main method consists of two nested loops, the outer iterates through all Account objects of the configuration, the inner through all keywords of the currently processed account.

Using tweet# is interesting: They heavily rely on .NET 3.5 extension methods to implement most of the functionality. The basic steps are outlined in the online documentation of tweet#:

  1. Create a request of what you want to get and specify your account login credentials.
  2. Retrieve the reply from Twitter and further process the reply.

Example for step 1:

var twitter = 
        .AuthenticateAs( account.UserName, account.Password )
        .Containing( keyword )
response = twitter.Request();

Here in this example, I authenticate an account with username and password, and then query for tweets with the given keyword. The result is then returned a string containing the JSON formatted result.

Example for step 2:

var searchResult = response.AsSearchResult();

The response is transformed into a search result collection. Here you have the ability to e.g. iterate through the results and further process them:

foreach ( var status in searchResult.Statuses )
    var userName = status.FromUserScreenName;

    // ... do something with the user name ... 


Depending on the kind of query, different object types are being returned. Again, please see the tweet# reference Wiki for full options.


Currently all output is written to console window only. Ususally next steps would be to use a logging framework like LOG4NET instead to log to various locations like e.g. e-mail or log files to get notified when something goes wrong.

Current state of the tool

The tool was a quick development of approximately 2 hours. It currently does exactly what I wanted it to do. Proably It does not even have any of the features that you want it to have.

Here you have at least two options:

  1. Download the source code and enhance it the way you want it.
  2. Tell me (down here in the comments section) which features are missing that I should add.

Of course option 2. would be helpful to me when enhancing.

As usual, I will enhance, extend and correct the tool over the next weeks and months. Keep the feedback coming!


  • 2009-11-06
    Updated to latest tweet# library.
  • 2009-06-29
    Added section that explains the internal code structure and some basic ideas behind the code.
  • 2009-06-29
    Added to Microsoft Codeplex and to Google code
  • 2009-06-28:

    Since at least four people (see their 1-vote comments below) seem to strongly dislike me and/or my article, let me summarize the motivation for this article:

    1. I searched Google for Twitter keyword auto-follow tools.
    2. I searched again.
    3. I found one tool,, which is usable only when paing money.
    4. I decided to write my own, as-fast-as-possible. So I used a third-party-library tweet#.
    5. I wanted to give others that want such a tool the opportunity to not start from scratch but to use my (thin) layer on top of tweet# as a foundation.
    6. I published the code as an article here at

    This said, I do know:

    • Neither the article nor the code is rocket science.
    • For me, this article is similar to all other articles I wrote, but somehow I must be mistaken.
    • I do love sharing and using code.
    • I also do love my company (really!) so I put hyperlinks to products of us in my profile section that appears under every article I write, not just this one.

    Thanks for reading!

  • 2009-06-26
    First version.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Uwe Keim
Chief Technology Officer Zeta Producer Desktop CMS
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

In his free time, he does climbing, running and mountain biking. Recently he became a father of a cute boy.

Some cool, free software from us:

Deutschsprachiges Forum zu Elektromobilität und Tesla  
Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
Homepage erstellen - Intuitive, very easy to use. Download now!  
Send large Files online for free by Email

Comments and Discussions

General5/5 - Thanks! Pin
JJMPSP19-Mar-12 8:42
MemberJJMPSP19-Mar-12 8:42 
GeneralTwitter! Pin
Uwe Keim29-Jun-09 9:32
sitebuilderUwe Keim29-Jun-09 9:32 
GeneralRe: Twitter! Pin
bobfox29-Jun-09 10:34
professionalbobfox29-Jun-09 10:34 
GeneralRe: Twitter! Pin
Uwe Keim29-Jun-09 10:39
sitebuilderUwe Keim29-Jun-09 10:39 
GeneralRe: Twitter! Pin
mbaocha25-Aug-09 12:34
Membermbaocha25-Aug-09 12:34 
GeneralMy vote of 1 Pin
Roberto Collina29-Jun-09 6:18
MemberRoberto Collina29-Jun-09 6:18 
GeneralRequest a rework of the article Pin
One Touch29-Jun-09 2:15
MemberOne Touch29-Jun-09 2:15 
GeneralRe: Request a rework of the article Pin
Uwe Keim29-Jun-09 2:31
sitebuilderUwe Keim29-Jun-09 2:31 
GeneralRe: Request a rework of the article Pin
Uwe Keim29-Jun-09 10:04
sitebuilderUwe Keim29-Jun-09 10:04 
GeneralRe: Request a rework of the article Pin
One Touch29-Jun-09 14:25
MemberOne Touch29-Jun-09 14:25 
GeneralRe: Request a rework of the article Pin
Uwe Keim29-Jun-09 19:49
sitebuilderUwe Keim29-Jun-09 19:49 
GeneralMy vote of 1 Pin
Saurabh.Garg28-Jun-09 18:48
MemberSaurabh.Garg28-Jun-09 18:48 
GeneralInteresting comments Pin
Hans Dietrich28-Jun-09 11:03
mentorHans Dietrich28-Jun-09 11:03 
GeneralRe: Interesting comments Pin
Uwe Keim28-Jun-09 18:54
sitebuilderUwe Keim28-Jun-09 18:54 
GeneralMy vote of 1 Pin
Rob Graham28-Jun-09 9:57
MemberRob Graham28-Jun-09 9:57 
GeneralMy vote of 1 [modified] Pin
Joe Woodbury28-Jun-09 9:05
professionalJoe Woodbury28-Jun-09 9:05 
GeneralRe: My vote of 1 Pin
Uwe Keim28-Jun-09 9:31
sitebuilderUwe Keim28-Jun-09 9:31 
GeneralRe: My vote of 1 Pin
Joe Woodbury28-Jun-09 10:01
professionalJoe Woodbury28-Jun-09 10:01 
GeneralMy vote of 1 Pin
TylerBrinks27-Jun-09 15:55
MemberTylerBrinks27-Jun-09 15:55 
GeneralMy reply [modified] Pin
Uwe Keim27-Jun-09 22:56
sitebuilderUwe Keim27-Jun-09 22:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.