For a little less than a year, I've been writing code built atop Twitter, specifically Matt Gemmell's MGTwitterEngine. I've got a few things running on this code, which I've not talked about publicly (other than minor hints on Twitter), but have been well-received by the few people who have seen it. Still, these projects have needed to extend both MGTwitterEngine and related libraries to add functionality or fix bugs. I'll spend this blog post documenting some of those changes across the different projects.
MGTwitterEngine
Most of these changes were made to make the engine's behavior a bit more extensible. Here's the GitHub repository.
MGTwitterEngineIDis a typedef for unsigned long long values. Everywhere a user ID or tweet ID is returned, it will return one of these. You will want to check your existing Twitter code to make sure there are no potential Twitpocalypse-related problems, updating old data types to the newMGTwitterEngineID.- Subclasses of
MGTwitterEnginecan now override a new method,-_sendRequest:withRequestType:responseType:, if they want to use custom networking code (such as with anNSURLRequestqueue class). I use this to implement both Twitter's password authentication and OAuth, and decide at runtime which to use. - Added a
-connectionStarted:method toMGTwitterEngineDelegate, which can be used to update your UI. - Fixed a few bugs in the YAJL parser which crashed or parsed incorrectly.
Things I still need to do:
In my custom subclass ofUpdate: Thanks to Uli Kusterer, the dependency onMGTwitterEngine, I use a class I wrote calledTCDownload, which I'll talk about below. There are still a few references to it in myMGTwitterEngineclass; those should be fairly straightforward to remove.TCDownloadhas been removed. The changes have been merged from his fork into mine.- Add full support for Twitter lists. I have some basic Twitter list functionality working in a private subclass, but far from all of it. There are some problems with the YAJL parser that don't appear easily fixable with the stock
MGTwitterEngine(specifically, the API key for the list description is the same as the key for the user's bio, and these are overwriting each other internally). I'm going to look into replacing the manual parsers - Add full support for new-style retweets. Haven't started this yet.
- Add support for geolocation in incoming and outgoing tweets. Haven't started this yet.
yajl
I've forked yajl to support 64-bit tweet IDs, mainly by changing the callback methods and the string parser from strtol to strtoull. Here is the GitHub repository.
SSCore
This is a repository of scattered classes which serve various purposes. There are two classes which are relevant for our discussion, TCDownload and TCOAuthDownload. You will need the TCDownload class if you use the vanilla MGTwitterEngine fork, although I'll be removing those dependencies. Here is the GitHub repository
TCDownloadis a generic wrapper that encapsulates an HTTP request to the interwebs. It wraps NSURLRequest and NSURLConnection under the hood. It automatically queues request and gets callbacks on a background thread (although you can change either of these). I use it a few places inside myMGTwitterEnginefork, but removed most of those changes and put them in a subclass.TCOAuthDownloadis a subclass ofTCDownloadwhich accepts OAuth tokens and sends out requests with the correct headers. It relies on theOAuthConsumerframework, which I'll talk about below.
OAuthConsumer
This framework deals with OAuth. Twitter has officially announced that basic auth will be dead in June 2010, so getting on the OAuth bandwagon now is a good idea. Here's my fork of the OAuthConsumer framework on GitHub.
- Changed the signature code to use Common Crypto instead of the C libraries' HMAC APIs. This seems to work more consistently on both Mac and iPhone.
- Added a
-parseHTTPKey:value:method which is used to parse extended attributes in OAuth access tokens. Twitter uses this to pass some special metadata, like the username of the logged-in user. Subclasses ofOATokencan extend this to parse those tokens.
OAuthery
This isn't strictly a tool for doing Twitter development, but it can be handy when learning how to implement the OAuth login flow. I posted about it more back in January, and you can find the code and a prebuilt app over at GitHub.
The Iranian anti-government protests are still occurring, months after the original protests occurred.
Credit to AFP/Getty Images, and Boston.com.
Twitter uses OAuth as its supported form of authentication. This is fine for some apps like clients where users need to authenticate themselves, but it doesn't work well for bots or scripts run by one person. If the bot needs an access token, it can be a real pain to obtain without writing the intermediate code.
This application, OAuthery, serves a simple purpose. You supply it the consumer key and secret for your OAuth application. It creates a request token and the URL for authorizing it. You complete the authorization in a web browser and get a PIN number. You then enter that PIN number back into the application, and it spits out your access key and secret. At this point, the user authentication is complete, and you can add those credentials to your script, and access API resources.
This is largely intended as a developer tool for people developing applications with Twitter's OAuth impelmentation. It also provides code to show exactly how to perform the authentication process with OAuth and Twitter, so that developers who wish to implement such functionality in their own apps can use this as reference.
Inactive, because it's a simple tool that serves a limited purpose.