. .


Twitter via xAuth: Working

October 2, 2010 13:35:09.003

I still need to integrate the work I've done with my blog tools, but I have Twitter access working from Smalltalk again. To do that, I had to build an xAuth interface. That wasn't hard, although it took a bit of research on my part to properly construct the authentication header. In any event, I posted the package OAuth to the public store repository. The OAuth implementation is not complete, but the simpler xAuth one is. To use it, you have to get keys from the service (like Twitter) that you want to integrate with. Then, you get your token:

auth := XAuthenticator fromSettings: (OAuth.Settings fromFile: 'twitterOAuth.ini').
tokenObject := auth executeXAuthAccessTokenRequest.

With the token retrieved, you should be able to do the following to update Twitter:

postCollection add: 'status' -> 'Testing xAuth to Twitter from Smalltalk'.
	executeXAuthCallFor: postCollection 
	with: tokenObject 
	to: 'http://api.twitter.com/1/statuses/update.json'

Now, Twitter doesn't want you to fetch a new token for each session; they want to get one, save it, and then use that (pretty much forever). So, I created a simple package - MiniXAuthTwit - that makes this simple. When it makes a token request, it'll store that token in a binary file (xAuthTokens.bos), and look for it before attempting to do a tweet. To use that package, all you do is:

MiniTwitPoster tweet: 'This is my tweet'

I started plugging this into my blog posting tools a bit ago, but never got around to finishing that. Looks like that's my next project :)

Technorati Tags: ,

posted by James Robertson

 Share Tweet This