Twitter .NET / C# Library
We promised to share a little, so here we are… sharing!
This time, we are sharing with you a .NET / C# class that wraps most of the Twitter API in an easy to use way, providing you direct access to the various methods and output formats used on the Twitter API.
This release includes all of the APIs except Direct Message methods (expect to see that soon).
The code is released on a “AS IS” basis with no guarantee or license. Do whatever you want with it, just remember that we are not liable in any way.
Giving us some credit will be nice, though
Twitt away, have fun and tell us some of the wonderful things you are doing with the library (hmm, wrapper)
Get the details, source code and a binary for .NET 2.0 here.

Feed (RSS)
Robert W. Crouch said,
August 6, 2007 @ 9:04 am
I was interested specifically in the Direct Message methods… did you ever post that?
Eran Sandler said,
September 2, 2007 @ 9:19 pm
Hello Robert,
Sorry for the late response. When I wrote this the direct_messages was not available. I will, however, add it soon (hopefully) and release an update.
Eran
Amish said,
February 2, 2008 @ 4:10 pm
Hi Eran, just checking if you have an update for direct_message. I added the methods below, and I expect it should work. I get response XML, however I don’t get a text message on my device. Note that I added a direct_messages object type, and a “New” action type.
————————————-
#region New Message
public string NewMessage(string userName, string password, string text, OutputFormatType format)
{
if (format != OutputFormatType.JSON && format != OutputFormatType.XML)
{
throw new ArgumentException(”Update support only XML and JSON output format”, “format”);
}
string url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Direct_Messages), GetActionTypeString(ActionType.New), GetFormatTypeString(format));
string data = “user=” + userName + “&” + “text=” + HttpUtility.UrlEncode(text).ToString();
return ExecutePostCommand(url, userName, password, data);
}
public string NewMessageAsJSON(string userName, string password, string text1)
{
return Update(userName, password, text1, OutputFormatType.JSON);
}
public XmlDocument NewMessageAsXML(string userName, string password, string text1)
{
string output = Update(userName, password, text1, OutputFormatType.XML);
if (!string.IsNullOrEmpty(output))
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(output);
return xmlDocument;
}
return null;
}
————————————-
Amish said,
February 2, 2008 @ 5:19 pm
Ok - found the prob. Here’s the full working method, need to distinguish between auth user and toUser:
—————————–
public string NewMessage(string authUserName, string password, string toUser, string text, OutputFormatType format)
{
if (format != OutputFormatType.JSON && format != OutputFormatType.XML)
{
throw new ArgumentException(”Update support only XML and JSON output format”, “format”);
}
string url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Direct_Messages), GetActionTypeString(ActionType.New), GetFormatTypeString(format));
//string data = string.Format(”user=(0}&text={1}”, userName, HttpUtility.UrlEncode(text).ToString());
string data = “user=” + toUser + “&” + “text=” + HttpUtility.UrlEncode(text).ToString();
return ExecutePostCommand(url, authUserName, password, data);
}
public string NewMessageAsJSON(string userName, string password, string text1)
{
return Update(userName, password, text1, OutputFormatType.JSON);
}
public XmlDocument NewMessageAsXML(string userName, string password, string text1)
{
string output = Update(userName, password, text1, OutputFormatType.XML);
if (!string.IsNullOrEmpty(output))
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(output);
return xmlDocument;
}
return null;
}
—————————–
Rick said,
February 11, 2008 @ 11:55 am
I am using the library to try and update my status. I am getting a 401 Unauthorized error. Do I have to sign up to be able to update this way?
Mohamed Faramawi said,
May 10, 2008 @ 11:22 pm
Thanks guys for taking the effort to write this code, i think you need to ask Twitter.com to list it under thier documentation website, they are listing every thing except the .NET.
anyway i used your library in making an msn messenger twitter Add-In and its working pefectly.
Thanks again