Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone provide a simple Python example for Twitter status updates?

I'm having problems to find a simple python twitter oauth example which shows how to post a user status on Twitter. Could you help me?

like image 364
Juanjo Conti Avatar asked Aug 25 '10 14:08

Juanjo Conti


Video Answer


2 Answers

Check out Mike Knapp's library on GitHub. Nice and simple, no install needed.

like image 75
stannie Avatar answered Sep 17 '22 17:09

stannie


Here's an example that will get you authed with Twitter using rauth.

After that point all you'd have to do to update the authenticated user's status is:

r = session.post('statuses/update.json',
                 data={'status': 'Updating my status from the cmd line.'})
print r.json()

(You only need to care about the code up until you retrieve your authenticated session object, i.e. line 20.)

Hope this helps!

Edit

You will need to get your own consumer_key and consumer_secret for this to work because the rauth demo app does not have write permissions, for obvious reasons. So you'll end up with this response if you try to run the modified script without updating the credentials:

{u'request': u'/1/statuses/update.json', u'error': u'Read-only application cannot POST'}

Ensure your application is allowed to write and it should work as expected.

like image 22
maxcountryman Avatar answered Sep 17 '22 17:09

maxcountryman