OLBTwitpicEngine: Twitter Image Uploading Code



OLBTwitpicEngine used in Light Table for iPhone

OLBTwitpicEngine used in Light Table for iPhone

Today we’re releasing source code for uploading and publishing UIImages from the iPhone to Twitter, via the TwitPic web service.

OLBTwitpicEngine is a simple class that takes care of it all, including uploading the image on a separate thread to keep the UI responsive. It also posts back a message to the delegate on success, including a link to the post. The OLBTwitpicEngine class was originally developed for use in our Light Table iPhone app.

We at OLB Productions and Lingon i Korg Software Creations have benefited from open source software code for a long time, and thought it was high time to start giving back.

Consider this our first tiny contribution. Free to use anywhere and anyhow, without restriction.

Download the .zip file from here. Then read the instructions in the .m file. Or clone the public git repository at GitHub.com.

8 Responses to “OLBTwitpicEngine: Twitter Image Uploading Code”

  1. 1 bo

    Thanks guys. This ought to be useful to a lot of people out there. Keep up the good work!

  2. This is fantastic work for the community. iPhone Development Communities are still somewhat behind in terms of being open and willingness to share. You’re definitely making a difference. Thanks a lot!

  3. The attached source code doesn’t work with my rails server. Gives a

    /!\ FAILSAFE /!\ Tue Mar 03 10:13:14 +1300 2009
    Status: 500 Internal Server Error
    bad content body

    I spent a day on this and it turns out you need to remove the first to newline characters from the form data. “/r/n” I think it is (or “/n/r”), just delete those and you are away laughing!

    Hope this saves you the 5 hours I spent on it!

  4. 4 avocade

    @Jordan: Thanks for the testing and the solution. We only used and tested this code against Twitpic.com for which it works fine. But we greatly appreciate you taking the time to make it work for any Rails setup.

    Also, as some have mentioned before in other forums; Optimally, the threading solution should be succeeded by a slimmer NSOperation-based structure. If anyone would like to take this on, we’re sure you would hear a lot of praise from happy concurrency-peeps.

  5. 5 Alan Taylor

    Hi, I am using the following code to call the method but it is giving me errors that I can’t seem to get round :/

    [OLBTwitpicEngine uploadImageToTwitpic:(UIImage *)TwitterPIC withMessage:(NSString *)TwitterMessage username:(NSString *)TwitterUN password:(NSString *)TwitterPW];

    Warining: ‘OLBTwitpicEngine’ may not respond to ‘+uploadImageToTwitpic:withMessage:username:password.’

    and the console gives:
    *** +[OLBTwitpicEngine uploadImageToTwitpic:withMessage:username:password:]: unrecognized selector sent to class 0x74a0

    Any help?

  6. I actually solved my error above by not using OLBTwitPicEngine, and instead just using a custom method – but thanks so much for showing me how it should be done – I could not have done it without you guys!!!

    I did find a bug though – if the username or password is incorrect TwitPIc will return an error but the status code is still 200. Because it’s pretty easy to make a typo on the iPhone, this is an annoying bug because it makes people think everything has worked when it actually hasn’t.

    here is how I got around the problem:

    NSString *searchFor = @”Invalid”;
    NSRange range = [responseString rangeOfString:searchFor];

    if ((range.location != NSNotFound) && (range.length == 7)) {
    NSLog(@”invalid username or password”);

    twitterLabel.text = @”Sorry – the username or password is invalid”;
    else if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300)

    this looks for the word "Invalid" in the response text, as the response that TwitPic gives is "urlResultString:

    I hope this helps people. This check may actually be in the OLBTwitPicEngine, but if not I’m sure that this text will be useful 🙂

  1. 1 Code: OLBTwitpicEngine at Under The Bridge
  2. 2 Upload a photo from iphone with 64 encoding multi part form data « Wetware.co.nz

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: