With the upcoming release of the Mac App Store, I can only imagine another gold rush is upon us. Clever Indie developers making money hand over fist while the store as well as developers find their identities. With that being said, I feel that there is a serious lack of interesting (maintained) Twitter clients for OSX. I say āmaintainedā because Tweetie for OSX is just fantastic, however Twitter said they donāt have any plans for it at this time. So, I want to provide devs with the tools to create an amazing Twitter client for the Mac that I will want to use
Quite some time ago, I began (and never completed) a series on writing a Twitter client for OSX. It was very well received by the development community, however once Twitter switched over to OAUTH, I became too lazy to update it . So, I figured a tutorial series for #iDevBlogADay would be the perfect opportunity to complete it.
So we are going to start from the ground up. In todayās tutorial, we are going walk through getting the initial resources and setting up Twitter to authenticate our application. We will also post a basic tweet.
In order for your application to interface with Twitter, you must register it with them over at http://developer.twitter.com.
I spent a bit of time researching the various options for handling OAUTH and all of the fun stuff that goes along with Twitter integration and found that MGTwitterEngine was the least painful to implement. I say least painful because it has a few quirks of itās own along with not having the best documentation in the world.
So after battling for a bit to get the thing compiled, I have figured out the setup process :). You could also read Mattās installation instructions, but I will regurgitate them here a little differently and hopefully be more clear. So here it is:
Altogether, this is the order of commands you should have:
<code class=ābashā>$ cd ~/Desktop $ git clone git://github.com/mattgemmell/MGTwitterEngine.git $ cd MGTwitterEngine $ git clone git://github.com/schwa/TouchJSON.git $ git clone git://github.com/ctshryock/oauthconsumer.git</code>
I find it interesting that this project is riddled with errors directly upon download. So much work went into it, yet itās so challenging to get working.
Now open up MGTwitterEngine.xcodeproj. You will notice that there are quite a few missing files (they show in red). Thatās fine. DELETE THEM ALLā¦
For todayās tutorial, we will just be displaying our timeline and updating our status using the demo file provided by MGTwitterEngine. In the next tutorial, we will actually be integrating the engine into a new project. So, open up AppController.m in the Demo group. Matt has given us some nice variables to fill in, in order to make this thing work. Letās update to applicationDidFinishLaunching method to look like the code below:
<code class=āobjcā>- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Put your Twitter username and password here: NSString *username = @"brandontreb"; NSString *consumerKey = @"aKKEsJHTDNsv4xVlMHmMqw"; NSString *consumerSecret = @"oldpeoplenakedcriscotwister";// Create a TwitterEngine and set our login details. twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self]; [twitterEngine setUsesSecureConnection:NO]; [twitterEngine setConsumerKey:consumerKey secret:consumerSecret]; [twitterEngine setUsername:username]; token = [[OAToken alloc] initWithKey:@"16369316-GgqA00WO0poCAj0XAFhJYDDRthVvWMxTnVyKdfWa1" secret:@"StrongEnoughForAManButMadeForAWoman"]; [twitterEngine setAccessToken:token]; [twitterEngine getHomeTimelineSinceID:0 startingAtPage:0 count:20];
}</code>
So obviously I changed my consumer secret and Access Token Secret. You will need to fill this out with your information. Here is how to obtain them.
Consumer Key & Consumer Secret
When logged into http://developer.twitter.com/apps/ , click on the application that you created in the first step:
Scroll down and you should see the Consumer Key and the Consumer Secret.
Access Token & Access Token Secret
In the right column, you should see a link titled āMy Access Tokenā. Click on it.
Now you should see YOUR Access Token and Access Token Secret
After you copy the tokens, keys, and secrets into the app, you should be able start making calls to Twitter using the engine. Build and run the application at this point and watch your home timeline get output to the console. One thing I want to point out is we are displaying an NSDictionary. That means MGTwitterEngine did all of the parsing for us (using TouchJSON), which is super rad.
One more thing to try for fun is to update your status. It will even show that you updated it from YOUR application on Twitter. Add the following line and run it again.
<code class=āobjcā>[twitterEngine sendUpdate:@"@brandontreb is a code gangster! Check out his #iDevBlogADay post on making your own Twitter client here http://bit.ly/gGrZvI"];</code>
Well, that does it for today. Join me next week when I will show you how to move the engine into your own project and we will begin displaying tweets in a basic table view.
Happy Coding!
—-