Originally published on: Sun, 24 May 2009 22:19:46 +0000
4/24/2010 - Please note: Twimmando may no longer function properly in a short while. Please see: http://www.mailsend-online.com/blog/twimmando-no-more.html

I joined Twitter about a week ago. I was aware of Twitter, but wasn't sure it'd be useful. I was pleasantly surprised to find a simple means of communicating with the masses.
As I looked through the Twitter documentation, I found reference to a RESTful API that was simple enough to use with cURL. In fact, most of the API samples illustrate a particular API function by using a cURL command-line.
I decided to tinker with the REST API and had a few programs that I had wanted to write, but I decided to start with a test harness of sorts: a simple command-line interface ( like a poor-man's version of cURL ... which is free and ubiquitous, so one would have to be *very* poor to use mine. )
I created Twimmando a simple command-line program written in csharp, compiled for .NET 2.0.
Twimmando has a simple command-line interface:
Twimmando v1.01
by Jim Lawless (@lawlessGuy)
Usage:
twimmando [options]
Where options are:
-uri resourceURI ; such as /statuses/public_timeline.xml
-u username ; Twitter password
-p password ; Twitter user name
-head ; send HTTP HEAD request, default is GET
-post ; send HTTP POST request, default is GET
-f name value ; add POST data name/value pair to request
For a list of REST API URI's, please see this document:
http://apiwiki.twitter.com/Twitter-API-Documentation
Let's just start by downloading the public timeline of Twitter posts anonymously as XML.
twimmando -uri /statuses/public_timeline.xml
You'll see a stream of XML go by in your display containing tweets (newest first) from everyone ... not just the friends you're following.
We can also download this data in JSON ( JavaScript Object Notation ) format or RSS ( Really Simple Syndication ) format by the two examples respectively:
twimmando -uri /statuses/public_timeline.rss
twimmando -uri /statuses/public_timeline.json
At this point, you could capture the information in a file in one of the above formats and can begin processing it with some other utility.
In order to invoke the REST API so that it functions under your Twitter user ID, you have to supply your user ID and password on the request.
The following command will download the list ( newest first ) of tweets that your friends have made.
twimmando -uri /statuses/friends_timeline.xml -u ID -p PASS
...where ID is your Twitter user ID and PASS is your Twitter password.
All of these documents are downloaded via the HTTP GET verb. I added support for the HTTP HEAD verb so that one could note the characteristics of a particular document and only process it if new information was present. It doesn't appear as if the Last-Modified header shows the date/time of the last tweet in the group. One might have to use the Content-Length header to determine whether or not a download would yield updated information.
To see the headers, add the parameter -head to your command-line above:
twimmando -head -uri /statuses/friends_timeline.xml -u ID -p PASS
To post a new update to Twitter, one must use the -post parameter and a field/value pair for the field "status".
twimmando -uri /statuses/update.json -f status "Hello from Twimmando!" -post -u ID -p PASS
The new tweet Hello from Twimmando! should show up in your personal history.
Note that Twimmando doesn't check the size of the status field to ensure that it posts within the 140-character limit.
I chose csharp as an implementation language as I'm planning to write something a little bigger than Twimmando and csharp was actually my choice for that project.
I began having difficulty when making a POST to the Twitter server. I had thought that I wasn't sending up credentials properly ... I received an HTTP 417 error. The exception condition arose because the HttpWebRequest class was sending up an Expect: 100 continue header with each POST.
To suppress that request header, I added the line below:
To add the credentials ( if present ) to a request, I used the snippet below:
To URL-encode the POST data string, I used a utility method from a class that is more likely to be associated with a .NET server process; System.Web.HttpUtility.UrlEncode().
I had originally intended to use a cookie storage file so that one would only have to authenticate once and would then simply serialize the cookies and deserialize them for each subsequent request.
I took a merry ride through the internals of CookieContainer and CookieCollection and found that the domain associated with the session cookie was ".twitter.com" ( note the leading dot ). When I changed the domain to "twitter.com", it appeared as though Twimmando was sending up the correct session cookie, but I was still encountering authentication errors.
I finally pulled out all of the cookie support, for now. I'll revisit this issue as time permits.
I tried running Twimmando under the Mono framework ( under Windows ). The EXE / assembly that I had compiled using the Microsoft .NET 2.x compiler ran, but then seemed to hang at the end of the process. I'm not sure why, yet.
You may download the source and .NET 2.0 EXE for Twimmando here:
http://www.mailsend-online.com/wp/twimmando.zip
Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless.
Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks
Click **here**
A JavaScript REPL for Android Devices
A Review of Kevin Mitnick's Book Ghost in the Wires
Play MP3 Files with Python on Windows
Screen Capture from Multiple Monitors in Java
Extending SpiderMonkey JavaScript on Windows
Directory Traversal in Rhino JavaScript
A Review of Kevin Mitnick's Book Ghost in the Wires
Windows Text to Speech in WSH JavaScript
Choose your own Adventure with Sinatra
Why Some Web Sites will go Dark on Jan 18th
Book Review : Paull Allen - Idea Man
A 90's Experiment in Online Systems - The U.S. West CommunityLink Service