24 Jul, 2009 in Programming by

.NET library for Twitpic photo API


Twitpic .NET API I needed to integrate an application into Twitpic for uploading pictures related to a Tweet.

So after spending a few hours reading over there API spec, I’ve created a simple class library for accessing Twitpics 2 remote calls:

Class Twitpic:

public Twitpic(byte[] media, string twitterUsername, string twitterPassword)
public TwitpicResponse UploadAndPost(string message)
public TwitpicResponse Upload()

Here’s a simple example using this class:

/* how you get an image to bytes is up to you */
ImageLoader img = new ImageLoader();
byte[] imageBits = img.ReadImage(thumbUrl);
/* i'm just downloading an image into a byte[] in this example */
Twitpic tp = new Twitpic(imageBits, AppSettings.TwitterUsername, AppSettings.TwitterPassword);
TwitpicResponse resp = tp.Upload();
imgThumb.ImageUrl = resp.MediaUrl;

In this simple example, I’m downloading an image off the web into a byte array. That array will be uploaded to Twitpic and if successful, you’ll get a TwitpicResponse which provides properties to access this uploaded image. Otherwise a TwitpicException may be raised indicating the error response received from the Twitpic API.

Download Twitpic.NET v1.0.

Please provide any feedback in the comments below!

Share on Twitter

7 Responses so far | Have Your Say!

  1. Wavatar

    Kamal Salem  |  October 8th, 2011 at 2:43 pm #

    I’m trying to use your library, I don’t want to upload photos, I just need to download them, however, when I try using the code above, I can’t find the class ImageLoader, any ideas?

  2. Wavatar

    Roger  |  October 10th, 2011 at 3:28 pm #

    Hi Kamal, the ImageLoader class referenced above is just a dummy class that doesn’t exist. It’s just showing that some local object is reading an image file into a byte array. A real option would be System.IO.File.ReadAllByes(“path:\to\file.ext”).

    Second, this class library is exclusively used for UPLOADING imaages and doesn’t provide any downloading features. Sorry for the inconvenience.

  3. Wavatar

    TOny  |  January 30th, 2012 at 10:35 am #

    Hi man, do you think you can share the source code? Actually I need a vb.net version so I did convert a certain C# twitter API library to vb.net. It’s working fine calling other REST API functions now except with uploading. The problem is that I cannot find any dotnet sample code (with open source) that does “statuses/update_with_media”. I cannot make my version work.

    Do you think you could help me out here? Here’s some lines of codes:

    Dim img As String = “images/balloonicon.png”
    Dim postData As String = “status=What the heck&media=” & img
    Dim rqstUrl As String = “https://upload.twitter.com/1/statuses/update_with_media.json”

    ‘ Build Signature Base String
    vow_Access.BuildSignatureBaseString(HttpMethod._POST, rqstUrl, postData)

    ‘Tell Twitter we don’t do the 100 continue thing
    ServicePointManager.Expect100Continue = False

    Dim hwr As HttpWebRequest = vow_Access.CreateWebRequest(postData, “multipart/form-data”)

    I am not sure if I can simply past a valid URL path of the image I like to upload. Or if I need to convert it to Base64 format, and the converted value is the value of my “media” parameter

    Thank you in advance.

  4. Wavatar

    Nidhi  |  August 4th, 2012 at 2:10 pm #


    I am getting invalid username and password error when I am using this dll in my windows application.

    Please provide me solution as soon as possible

  5. Wavatar

    pratap  |  August 24th, 2012 at 10:49 am #

    hi roger , i tried to implement your code for uploading image to twit pic from my c://test. jpeg. it was showing an exception that the username and password are not correct. i was hard coding username and password without using app settings is that a problem. if not please let me know how could i resolve this issue?. i was working on this for this for the past four days .please help me.

  6. Wavatar

    Surinder  |  August 28th, 2012 at 7:59 am #

    I created a simple .NET library that can output Twitpic images. Take a look here: http://www.isurinder.com/blog/post/2012/08/28/NET-Library-To-Retrieve-Twitpic-Images.aspx.

  7. Wavatar

    Jack  |  September 9th, 2012 at 2:13 am #

    I found a good .net library to get images from a user gallery: http://www.isurinder.com/blog/post/2012/08/28/NET-Library-To-Retrieve-Twitpic-Images.aspx