LocustHorde
LocustHorde

Reputation: 6409

How to wrap oAuth headers in clj-http?

I'm trying to post a twitter status update with clojure... but this probably really is a question about oAuth headers, and using it through the wonderful clj-http library.

I've used clj-http before for basic-auth and other type of headers and it was fairly straightforward. The Authorization: Bearer ... was a bit confusing but I got there in the end.

For twitter though, I am supposed to pass a lot of variables in Authorization and I am not quite sure how I'd go about doing that. Here's the curl command, according to twitter, that I'll need to post the tweet:

curl --request 'POST' 'https://api.twitter.com/1.1/statuses/update.json' 
     --data 'status=this+is+sparta' 
     --header 'Authorization: OAuth oauth_consumer_key="xxxxx",
                              oauth_nonce="xxxxx", 
                              oauth_signature="xxxxx", 
                              oauth_token="xxxxx", oauth_version="1.0"' 
     --verbose

So I am not sure how I would append all the oAuth... things in the header. trying with (str ..) isn't really working out. Here's what I've got so far:

(client/post "https://api.twitter.com/1.1/statuses/update.json")
             {:headers {:Authorization (str "OAuth oauth_consumer_key='xxxxx', oauth_nonce='xxxxx', oauth_signature='xxxxx', oauth_token='xxxxx', oauth_version='1.0'" )}
              :form-params {:status "This is sparta"})

This returns 403. permission error when I try.

Any ideas on how I'd construct that query?

ps: I do have the oAuth token and token_secret for the account... but I notice the token_secret value isn't being passed? and what does oauth_nonce for? I'm for now passing the value that twitter gave me for curl... looking around it seems that it is just a random value so not that fussed about it.

Upvotes: 2

Views: 1603

Answers (2)

iamserious
iamserious

Reputation: 5475

I've had difficulty in the past trying to use clj-oauth (mostly because of my own understanding of clojure) but I found twitter-api pretty straightforward to use. It makes use of clj-oauth internally.

Upvotes: 2

pete23
pete23

Reputation: 2280

It might be worth taking a look at Matt Revelle's OAuth client library for Clojure. https://github.com/mattrepl/clj-oauth

OAuth is sufficiently non-trivial to make it tiresome to hack together something from bare bones. If nothing else and you still want to go the minimal route, you might get some ideas.

Upvotes: 3

Related Questions