A newbie joins twitter and after a while starts to pick up in this amazing world of social media. Then someday he spots a tweet from one of his following and it’s from a client with his name. I have been in those shoes and went like ‘I want this’. There are various ways of building a twitter app most of which are tedious as they require lots of setup and above all, require prior knowledge in coding with some programming languages. That might be a miss for a person like me who was just starting on python-django framework.

For this to work. You must have a python installation on your computer so probably it will be relevant and make sense quite easily to python users. I took the steps bellow to creating my new twitter client; tweets posted from my Ubuntu terminal.

 Step 1: Downloading Tweepy.

Tweepy is a twitter library python that basically handles all twitter functionalities per say. You can install it in your system using pip install tweepy or downloading it from https://github.com/tweepy/tweep then manually installing it.

Step 2: Creating a new twitter application with Twitter.

Log into your twitter account then navigate to http://twitter.com/apps/new to create a new client. It should look as below. Fill in the details making sure the access type is read & write. The name you give is what will appear in you tweet as via say me. Click save once you are done. The next page will be the OAuth tool page will have Consumer key, Customer secret, Access key and access secret. Take note of them.

Image

Creation of a new twitter client

Step 3: Connecting Twitter account to the client.

Open the python shell (type python on the terminal). Then input the following filling in your Customer key and secret from the OAuth tool page.

>>> import tweepy

>>> auth = tweepy.OAuthHandler(‘PASTE YOUR CONSUMER KEY’, ‘PASTE YOUR CONSUMER SECRET’)

>>> auth_url = auth.get_authorization_url()

>>> print ‘Please authorize: ‘ + auth_url

Copy paste the generated url to your browser and navigate to it. You should see the window as below. Click on authorize app and some PIN will be generated for you. Enter the PIN in the terminal and proceed as below.

Image

Authorizing the twitter client

>>>auth.get_access_token(PASTE_YOUR_PIN)

>>> print “ACCESS_KEY = ‘%s’” % auth.access_token.key

Make a note of this ACCESS_KEY

>>> print “ACCESS_SECRET = ‘%s’” % auth.access_token.secret

Make a note of this ACCESS_SECRET

Step 4: Sending tweet from the terminal via your client.

Open a new python shell and enter the following replacing it with your OAuth values.

>>> import tweepy

>>> auth = tweepy.OAuthHandler(‘PASTE_CONSUMER_KEY’, ‘PASTE_CONSUMER_SECRET’)

>>> auth.set_access_token(‘PASTE_ACCESS_KEY’, ‘PASTE_ACCESS_SECRET’)

>>> api = tweepy.API(auth)

>>> api.update_status(“YOUR TWEET”)

In the last line, the values in the bracket ie YOUR TWEET becomes your tweet. You can replace it with what you want to tweet. If it goes well, that tweet should appear in you timeline. Save the following as a script in your system(use .sh extension) as below and know that you have understand, you need to paste your values.

Image

script to save

To send a tweet. Open terminal then to open type ./NameOfYourScript.sh “YOUR TWEET”. It should send your tweet to your timeline. There we go. Enjoy having to tweet from terminal that basically ends up having your tweets posted from your client.

Advertisements