0

I've been using Tweepy for OAuth and twitter API calls. For a whole bunch of reasons, I'm switching to urllib and making HTTP requests directly.

It appears have two options:

  • I can do oAuth directly over HTTP, but the existing resources seem to either say "don't bother, just use a library," or they don't cover half of the process.
  • I can continue using Tweepy to get a key/secret pair, but from there I'm still not clear on how to use that pair to authenticate my queries. Specifically, what do I have to do before "https://api.twitter.com/1/statuses/home_timeline.json" to authenticate, supposing I've already completed the OAuth process and have a key/secret for the user I want.

1 Answer 1

2

Why don't you use a more generic oauth library (like oauth2), instead of throwing out the oauth authentication library idea entirely?

https://github.com/simplegeo/python-oauth2

Signing a request for OAuth means either implementing the signature function yourself for each request or using an existing library - and creating oauth signatures is pretty complicated and prone to breakage. As someone who's supported OAuth-based APIs for a couple of years I strongly encourage you to use a library.

The oauth2 library has an example for getting a token/secret for twitter.

Once you've gotten the token and secret, the oauth library is as simple as:

consumer = oauth.Consumer(consumer_key, consumer_secret)
token = oauth.Token(token,secret)
client = oauth.Client(consumer,token)
response = make_request(client,"https://api.twitter.com/1/statuses/home_timeline.json")
4
  • Awesome, this is really helpful. However, I;m having trouble finding the example for getting a token you referenced. Is it in the GitHub, and do you have a link? Jan 4, 2012 at 0:44
  • Also, where is the make_request function? I can't seem to find it in OAuth2 code anywhere. Jan 4, 2012 at 1:21
  • If you go to the github repository for python-oauth2, look for "Twitter Three-legged OAuth Example" on that page (in the Readme, so in the main doc). That should get you going - it's the example we used as the basis for the LinkedIn Python token docs. Jan 4, 2012 at 16:17
  • Thanks a lot, you've been a huge help! Jan 5, 2012 at 3:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.