Post tweets to twitter using python


This post is about how python can be used to post tweets in twitter. To get started with this we need to install twitter for python which can be done from http://code.google.com/p/python-twitter/ . It really has a very good documentation of installing twitter. To verify the process is similar like other ones, you just need to run "python -c 'import twitter" in terminal and if no errors intallation was successful. That means we can proceed.


Lets create a twitter application now. To create a twitter application go to https://dev.twitter.com/apps .Once you create the application you need to put Access token, Access token secret, consumer key, consumer key secret into the code as follows:
#!/usr/bin/python
from twitter import *
t=Twitter(auth=OAuth('Access token', 'Access token secret', 'Consumer Key', 'Consumer Secret'))        
status_text=raw_input('Enter your message: \n')
t.statuses.update(status=status_text,source="http://usepython.blogspot.com/")

Now you can try running the code, it will ask for a text to tweet once you supply text and hit 'ENTER'  key, your text will be tweeted to twitter.
To get tweets of your friends you can use
latest=t.statuses.user_timeline()
If you want to get tweets by yourself you can use
mytweets=t.statuses.home_timeline()
*One key point to note is Acess should be Read and Write.

Comments

Popular posts from this blog

Automate file upload in Selenium IDE

How To Install and Configure Nextcloud