Call Twitter APIs from C# .Net

Twitter has an API implementation that is very simple to understand and use. Here is how it works, if you want to get the friends timeline of a user.

http://twitter.com/statuses/friends_timeline.rss

Here there are 3 keywords.
What are you working on? statuses
What do you need from the above object? friends_timeline
In what format do you need it? RSS

Formats supported are: xml, json, rss, atom
Methods supported: See Twitter API
There are many objects supported, but the above format applies for only a few like Statuses, User, Direct Messages. The rest are also similar.

Now, let us look at a GET to bring in Friend Status.

First off, we would need the URL above

The public method GetFriendsStatus calls a generic method InvokeAPI to (surprise!) invoke the API. This function in turn relies on GetUrl to build the URL for this request. AskTwitter is a helper method that does a GET request and returns the result.

As you can see, AskTwitter takes in 2 parameters. First one is the URL we built earlier. The second parameter is user credential, for requests that require credentials. This can be built easily as below.

Hope that helped get you started. Am working on a complete set of wrappers that will make using these APIs much more easier. Please leave a comment and let me know if you would be interested in any specific features.

One thought on “Call Twitter APIs from C# .Net

  1. I am trying to retrieve latest post from a private twitter account.Currently I am using basic authentication to get the latest post.I am not sure if basic authentication is the best way of doing it.I have read about Oauth to retrieve post.Do you have any code or APIs I can use to make oAuth authentication.Code snippet would be very helpful.

    Thks,
    Schwab

Leave a Reply

Your email address will not be published. Required fields are marked *