I had a quick look into the Twitter API today. It turns out it was quite easy to get started and to quickly develop a twitter application.
Resources
The main Twitter API documentation page is located at http://apiwiki.twitter.com/Twitter-API-Documentation.
There are two .NET twitter clients available
- tweetsharp, http://code.google.com/p/tweetsharp/
- twitterizer, http://code.google.com/p/twitterizer/
Choices, choices
I decided to use tweetsharp because it seemed to be the most complete and easiest to use. The examples that are provided in the client are pretty good. It seems that to make calls to some of the API, you need to be authenticated with Twitter. You can either do this directly, ie. by specifying your username and password or by using OAuth.
For example to get a list of followers, the following is called using the specified username and password
var twitter = FluentTwitter.CreateRequest()
.Configuration.UseGzipCompression()
.AuthenticateAs(UserManager.Username, UserManager.Password)
.Users()
.GetFriends()
.AsJson();
var response = twitter.Request().AsUsers();
If you were using OAuth, it would look like the following instead
var twitter = FluentTwitter.CreateRequest()
.Configuration.UseGzipCompression()
.AuthenticateWith(consumerKey,
consumerSecret,
accessToken,
accessSecret)
.Users()
.GetFriends()
.AsJson();
var response = twitter.Request().AsUsers();
Now, you're probably wondering what's the consumerKey, consumerSecret, accessToken and accessSecret. The consumerKey and consumerSecret is specified manually and are obtained when you register your application (I will come to this later). The accessToken and accessSecret is obtained when the user uses your application and authorizes your application to access their information.
Application Registration
To use OAuth, you will need to register your app with twitter at http://twitter.com/oauth_clients. However, there is one problem. You can't specify a localhost address with a port number for the Callback Url. The Callback Url is what Twitter will redirect you back to when the user decides to deny or allow access their information. Bummer. But it's not the end of the world. When the user, you in this case since you'll be testing it locally, authorises your app, you just need to update the Callback Url in your browser to point to your local development server, eg.
http://sss.cloudapp.net/login?oauth_token=p93nRpiD1R5C1gRk2Mk27ocTXVfzGPhK8vT9V4
to
http://localhost:8080/login?oauth_token=p93nRpiD1R5C1gRk2Mk27ocTXVfzGPhK8vT9V4
Storing the access keys
After obtaining the accessToken and accessSecret, you will need to store it somewhere so that the user does not need to do the authorization bit everytime they use your app. For me, I store them in cookies.
And that's it.