Twitter is a popular application used amongst many different age groups, people, companies, and associations. I do own a Twitter myself (@DigitalEmpress) and I enjoy the versatility it provides. I get to use it for so many different things such as networking, sharing ideas, marketing myself, and catching up with the latest news. Twitter’s first launch of the Twitter application was called “Tweetie” to be able to social network via website. This project demonstrates how to use Twitter’s API (Application Programming Interface) to send and receive messages from programs rather than from the Twitter app or the website.
The first thing you will need for this project is a Twitter module. Now mind you, I was a bit hesitant to follow through with this project because we all know my past struggles with python modules. I took a leap of faith with this one and downloaded it just so I can have further confirmation that python modules and I do not get along just in case I ran into the issue again. I downloaded the twitter module from this link, https://github.com/sixohsix/twitter, and built the module accordingly in my terminal.
python3 setup.py build
sudo python3 setup.py install
The chapter also suggested I create another Twitter account so that I can send test tweets instead of sending these to my regular account. I created a new twitter account (@mermaidsecurity) and decided to use this one solely for developing purposes. After creating my account, I signed my Twitter application up through their Application Management website (apps.twitter.com). This is an application interface that offers the ability to generate OAuth access tokens for the application owner. In the book, it instructs you to go to dev.twitter.com, which is a place for developers to gain more information about the Twitter’s API and how it can be used for their own apps. I first signed up to this one thinking this is where I will get my tokens but it is not the right website. (Headsup)
Here you are going to create an application by signing it up with a unique name and adding a 10-character description. You will also have to sign up a website for it to go through successfully. Not any website will work so I did some research and came across this one, http://url.com, which should work for completing the sign-up process.
After agreeing with the terms of service I had to go in and create an access token. The access token can be created on the “Keys and Access Tokens” tab and clicking the “Generate my Token” button in the Application Manager. The website will then refresh and provide you with an “Access Token” and an “Access Token Secret”. These keys are important because this is what you will be using to insert into your code so when ran the program will know what account to send the tweet too. The program will also need the “Consumer Key (API Key)” and the “Consumer Secret (API Secret)” to work.
Once the keys have been copied and pasted into correct spot the code can be run successfully. I ran the code on both my Macbook and Raspberry Pi terminals using the 3.5 version of python. I noticed that when it is running in the python shell the stack trace gets very angry and does not allow you to tweet. When ran in the terminal it shows your accounts most recent tweets and asks if you want to search anything. I continue along to press enter to start tweeting. Unfortunately, it only lets you tweet one tweet and then the program closes out but I think it’s still awesome that I can tweet directly from the terminal on my Macbook or Raspberry Pi.