I'm trying to work with the OAuth interface to Twitter - I haven't gotten very far, as I get a 401 on every attempt to request a token. Here's the workspace code I've been experimenting with:
url := 'http://twitter.com/oauth/request_token'.
nonce := Timestamp now asMicroseconds asByteArray asHexString.
parms := Dictionary new.
parms at: 'oauth_consumer_key' put: twitConsumerKey.
parms at: 'oauth_version' put: '1.0'.
parms at: 'oauth_timestamp' put: Timestamp now asUnixSeconds printString.
parms at: 'oauth_signature_method' put: 'HMAC-SHA1'.
parms at: 'oauth_nonce' put: nonce.
keys := parms keys asSortedCollection.
text := twitTokenReqUrl.
encoded := OS.URI encode: text.
stream := WriteStream on: String new.
stream nextPutAll: 'GET&', encoded.
keys do: [:key |
stream nextPutAll: '&', key, '=', (parms at: key)].
sigBase := stream contents.
okey := twitConsumerSecret, '&'.
sig := ((HMAC SHA: okey asByteArray) hash: sigBase) asBase64String.
keys add: 'oauth_signature'.
parms at: 'oauth_signature' put: sig.
client := HttpClient new.
request := client requestClass method: 'GET' url: url.
request contentType: 'application/x-www-form-urlencoded'.
keys do: [:each |
request addFormKey: each value: (parms at: each)].
client executeRequest: request.
Anyone see anything obviously wrong in that? I'm looking at the Twitter API pages and the OAuth spec pages...
Technorati Tags:
oauth, twitter