Post a tweet to Twitter using python

In our last article we have seen how to get our followers and following list and write those names to an excel sheet. If you have not read the article please go and have a look.

In this article we are going to tweet from python using the “twitter-python”. The prerequisites and the steps to get the api keys are also in the previous article. So we shall jump right into the code in this article.

The code

We are going to use the “PostUpdates()” api to post a data(tweet) to Twitter. We shall need the following four keys for that.

  1. API key
  2. API secret key
  3. Access token key
  4. Access token secret key

once we have that we can post our tweet to Twitter like this.

tweet using twitter python

Go to your twitter account and check out your timeline for the tweet. Let me show you my tweet.

tweet from python

We shall see the other available methods in upcoming articles. The twitter-python module has so many methods that we can make use of. Keep doing wonderful things with python.

Happy coding!