How to Send a Tweet from Python? I can read, but not post.

S

saqib.ali.75

I posted this on StackOverflow.com but haven't got a good response yet: http://stackoverflow.com/questions/14808245/python-why-cant-i-send-a-tweet



I have tried two different packages python-twitter and tweepy but have not been successful using either package. Those solutions are discussed here:

Twitter API: simple status update (Python) How to tweet from Django?

Firstly, I should make clear that I have just created a Twitter account a couple of hours ago from which to send tweets. Using dev.twitter.com, I haveset the access level to "Read, write, and direct messages" and I have created consumer and access token keys.

Using these keys, I connect to twitter using the python-twitter package. I know it is at least partially working because I can access The Biebs tweets:

http://t.co/q58qksxp its not finished but heres a little part a song I'm working on
sorry http://t.co/Vtu4Lc2Q
video is at 13 percent done uploading

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/python_twitter-0.8.5-py2.7.egg/twitter.py", line 2838, in PostUpdate
data = self._ParseAndCheckTwitter(json)
File "/usr/local/lib/python2.7/dist-packages/python_twitter-0.8.5-py2.7.egg/twitter.py", line 3869, in _ParseAndCheckTwitter
self._CheckForTwitterError(data)
File "/usr/local/lib/python2.7/dist-packages/python_twitter-0.8.5-py2.7.egg/twitter.py", line 3892, in _CheckForTwitterError
raise TwitterError(data['error'])
twitter.TwitterError: Could not authenticate with OAuth.
Can someone explain why? Since that didn't work, I decided to install and try tweepy.

But when I try to use it, it gives me the error "Invalid or expired token"

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 11, in tweet
File "/usr/local/lib/python2.7/dist-packages/tweepy-2.0-py2.7.egg/tweepy/binder.py", line 185, in _call
return method.execute()
File "/usr/local/lib/python2.7/dist-packages/tweepy-2.0-py2.7.egg/tweepy/binder.py", line 168, in execute
raise TweepError(error_msg, resp)
tweepy.error.TweepError: [{u'message': u'Invalid or expired token', u'code': 89}]
What is the solution here? Are my keys from Twitter wrong?
 
S

Steven D'Aprano

I posted this on StackOverflow.com but haven't got a good response yet:
http://stackoverflow.com/questions/14808245/python-why-cant-i-send-a-tweet



I have tried two different packages python-twitter and tweepy but have not
been successful using either package. Those solutions are discussed here:

Twitter API: simple status update (Python) How to tweet from Django?

These are not URLs.

Your question is very specialised. If you don't get a response in a day or
so, you may have better luck asking on a dedicated python-twitter or tweepy
forum, or if those projects are too small to have a dedicated forum, by
asking the creator of the packages for assistance.

If you do get an answer somewhere else, please reply here with the solution
to help future developers who are searching for an answer to the same
question.

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top