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.

25 Comments »

  1. Robert W. Crouch said,

    August 6, 2007 @ 9:04 am

    I was interested specifically in the Direct Message methods… did you ever post that?

  2. 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

  3. 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;
    }
    ————————————-

  4. 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;
    }
    —————————–

  5. 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?

  6. 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

  7. Daily Find #87 | TechToolBlog said,

    July 10, 2008 @ 4:35 am

    [...] C# twitter library – using it on a project I am working on [...]

  8. Weekly Link Post 50 « Rhonda Tipton’s WebLog said,

    July 13, 2008 @ 3:03 pm

    [...] Eran Sandler provides us with a link to Twitter .NET / C# Library. [...]

  9. Twitter Portlet/Gadget for Webcenter Interaction (ALUI) Part 2 (Robert Herrera's Blog) said,

    September 3, 2008 @ 10:02 am

    [...] some kind of wrapping class for the twitter calls. Enter the yedda api’s that are freely available here. I had discovered them some months back and had simply moved them to a todo folder. Little did i [...]

  10. craig dugas said,

    September 25, 2008 @ 11:38 pm

    Twitter API via C#…

    Twitter offers a nice little REST-based API, which allows for limitless platforms to develop some basic Twitter applications.  To make this even easier for the C# developer, Yedda provides a free library wrapper class for the Twitter API. It’s t….

  11. Ryan said,

    December 28, 2008 @ 9:58 pm

    I am using the Yedda C# twitter wrapper for my project at twAitter.com. Thanks for taking the time to write this code.
    I saw that Twitter finally listed your api on their site.

    Ryan

  12. Nik Smit said,

    January 19, 2009 @ 10:36 am

    Be aware twitter have made changes which breaks this a bit. Fix with the line

    System.Net.ServicePointManager.Expect100Continue = false;

  13. Eran Sandler said,

    January 26, 2009 @ 5:56 am

    Thanks for the heads up Nik!

  14. Rodney Joyce said,

    January 26, 2009 @ 7:16 pm

    Hi Nik,

    Can you elaborate where to insert that line please?

    Thanks!

  15. @TweetSG » Blog Archive » Running your own Twitter SMS Gateway - Free SMS Tweeting to a Singapore number! (aka Twitter.sg) said,

    February 24, 2009 @ 6:26 pm

    [...] to SMSLib C# (C# version is deprecated) and Eran Sandler for his C# Twitter wrapper. Without these great components, this gateway software will take me a longer time to develop. It [...]

  16. Thimp said,

    March 11, 2009 @ 3:08 am

    The Service point manager attribute is used for new ServicePoints, so it does not work all the time.

    A solution is to use a HttpWebRequest:

    HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

    then disable the Expect Header:

    request.ServicePoint.Expect100Continue = false;

    Thanks for the API (or should I say wrapper)

    Thimp

  17. rams said,

    April 1, 2009 @ 7:17 pm

    Thanks for the simple wrapper. This has made my code easier to write!

  18. Darren Hart said,

    April 7, 2009 @ 7:24 am

    Managed to get it working in .net 1.1 with only two minor tweaks

    - one of the classes referenced using System.Collections.Generic doesn’t exist in 1.1, but seems to work with using System.Collections anyway
    - IsNullOrEmpty doesn’t exist in 1.1 but you can test for nulls in other ways

    Otherwise great stuff!

    have already wowed lots of people by automating twitter feeds via a database update, and to create a list of tweets directly into a particular layout

  19. F#: A day of writing a little twitter application at Mark Needham said,

    April 13, 2009 @ 4:12 am

    [...] a request for suggestions for a .NET twitter API. It pretty much seemed to be a choice of either Yedda or tweetsharp and since the latter seemed easier to use I went with that. In the code you see at [...]

  20. Nizar said,

    June 16, 2009 @ 8:11 am

    Eran,

    Have you made the modifications as per the 1.0a release that requires the oauth_callback to be passed during request_token. I am having some difficulty to make that work and was wondering if you had it already got it figured out and would mind sharing the code.

  21. Claudiu T. said,

    July 14, 2009 @ 11:01 am

    I’m a newbie at C#, can you please explain how do I integrate this into my project?

    Thanks.

  22. Twitter Trackbacks for Yedda Dev Blog » Twitter .NET / C# Library [yedda.com] on Topsy.com said,

    August 31, 2009 @ 12:11 am

    [...] Yedda Dev Blog » Twitter .NET / C# Library devblog.yedda.com/index.php/2007/05/16/twitter-c-library – view page – cached 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. — From the page [...]

  23. Ananda said,

    September 4, 2009 @ 3:49 am

    i am using Yedda api to post to twitter
    i am getting 408 response time again
    can any one suggest why is this happening

    thanks
    anand

  24. Raul said,

    September 15, 2009 @ 8:54 am

    Can you post some starters examples on how to use your api?
    Thanks!

  25. Eran Sandler said,

    November 12, 2009 @ 2:31 pm

    @Nizar – the Yedda Twitter API wrapper is for the old password based API which shouldn’t be used at all. The OAuth based API has numerous great libraries that you should use instead.

    @Ananda check the code at http://github.com/erans/twitter-csharp-library although you should move to one of the OAuth based C# libraries. You can find a list in the Twitter API wiki

    @Raul it is best for you to move to some of the OAuth based C# libraries. You can find examples in some of the libraries packages. Look for the libraries at the Twitter API wiki page

TrackBack URI

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word