Papermashup

Subscribe


Tweets


"RT @bethgordon: .@Tesco Please rethink archaic 'Approved by Mums'. Pretty sure it's not just mothers who make childcare decisions. https://…"

@ashleyford 14 hours ago

"Is there ever a time that @DFS doesn't have a sale on?"

@ashleyford 4 days ago

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Papermashup

Twitter CLI using “t”

Have the power of Twitter and more through the command line. Save your tweets to CSV, bulk unfollow people, and perform search queries.

AshleyAshley

I stumbled across this awesome command line interface that allows you to do some pretty cool stuff with Twitter. To get started you need to install the Ruby GEM.

On Mac

first check that you have Ruby installed.

$ ruby -v

If you see something like this you’re good to go.

$ ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

However if you see the below you’ll need to head over here and install Ruby.

$ ruby: command not found

On Linux

You can install Ruby like this.

$ sudo apt-get install ruby-dev 

or for Red Hat-based distributions like Fedora and CentOS just type:

$ sudo yum install ruby-devel 

On Windows

you can install Ruby with RubyInstaller.

Install the “t” GEM

$ gem install t 

Setup

The Twitter API requires OAuth for all of its functionality, so you’ll need a registered Twitter application. If you’ve never registered a Twitter application before. Just sign-in using your Twitter account and then fill out the short form at http://dev.twitter.com/apps/new. If you’ve previously registered a Twitter application, it should be listed at http://dev.twitter.com/apps. Once you’ve registered an application, make sure to set your application’s Access Level to “Read, Write and Access direct messages”, otherwise you’ll receive an error that looks like this:

$ Error processing your OAuth request: Read-only application cannot POST 

One you’re all set you just need to call

$ t authorize 

This command will direct you to a URL where you can sign-in to Twitter, register your apps API key and Secret, then enter the returned PIN back into the terminal. If you type the PIN correctly, you should now be authorized to use t as that user. To authorize multiple accounts, simply repeat the last step, signing into Twitter as a different user.

What can we do now?

To see all the commands you can use simply type:

$ t help 

Lets now send our first tweet!

$ t update "This tweet is being sent from the command line!" 

Example Usage

Screen Shot 2015-06-04 at 21.29.42

View your timeline

Screen Shot 2015-06-04 at 21.32.23

That’s not all!

There’s a whole heap of cool stuff you can do now, this is just the beginning. you can download your tweets in CSV format you can unfollow people, check if someone follows you, create a list and add everyone you’re following, unfollow 10 people who haven’t tweeted in a long time. Here are a few of my favourites:

Mute everyone you follow

$ t followings | xargs t mute 

fetch detailed information on a user

$ t whois @ashleyford 

Unfollow everyone you follow who doesn’t follow you back

$ t leaders | xargs t unfollow 

Backup your tweets to CSV

$ t timeline @ashleyford --csv --number 300 > tweets.csv 

You can check out more information here on how to use “t” along with more examples of it’s usage. It’s a great little geeky tool to have and means you can look busy in the office whilst checking Twitter which is always good!

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Comments 1