Take the 2-minute tour ×

Is there a simple way to retrieve someone's tweets from the command line?

The account would be public, and the command - or script, if necessary - would retrieve all or a specified number of most recent tweets to a text file, one tweet per line, without the metadata, the newest in the first line.

Without the use of API, only bash.

share|improve this question
use python api, easy and sweet –  BigSack Nov 1 '12 at 7:57
not the way I would prefer, but out of curiosity which python API, any link, or is it in the repositories? –  Strapakowsky Nov 1 '12 at 8:29
There is python-twitter API wrapper. –  jokerdino Nov 1 '12 at 12:58
add comment

2 Answers

up vote 2 down vote accepted

From a-close-date on, Twitter won't let you into their API without having an OAuth key. But as a workaround you can use Search API. It is RESTful, so you can use curl to retrieve search results in JSON format. For example, if you want to retrieve @java's tweets, and save it to file ~/.tweets, this line of code can be used:

curl http://search.twitter.com/search.json?q=from:java&page=1&rpp=10&callback=? >> $HOME/.tweets

And you can parse the file, using any JSON parser.

The rpp parameter is number af tweets to be retrieved. callback is javascript function to be executed on the resulting JSON. In case you're not using JavaScript with the api, you can leave it ?, but don't remove it. I will cause an error. More guidance on Search api can be found on https://dev.twitter.com/docs/api/1/get/search

There are tools to parse JSON from command line interface. Although I've never used one, I'll put some links to some resources, to help you find out the best suited tool:


And as a little note, it is quicker to use some Python or Ruby (or others).

share|improve this answer
Looks good, thank you @g_kaya. How can I specify, for example, all tweets, or the maximum allowed, or 400 tweets? What is the callback and the rpp options? Can you recommend a command-line JSON parser? –  Strapakowsky Nov 3 '12 at 5:54
I've edited my answer as per your questions. Hope it helps :) –  cadadr Nov 3 '12 at 6:12
Thanks for the many JSON parsing options. –  Strapakowsky Nov 3 '12 at 7:18
I'm glad if they're useful, you're welcome :) –  cadadr Nov 3 '12 at 7:35
add comment

If you don't want to use the Twitter API, you could grab the RSS feed of the Twitter profile using a bash script and then proceed to format it from there.

Since Twitter API has deprecated the RSS feed, you can workaround this by generating RSS feed using the search results.

Here's the RSS feed of my tweets.

You would have to put together the necessary bash script though. From fetching the RSS feed to formatting the tweets as per your requirements.

share|improve this answer
Thanks @jokerdino. I am fine with formatting the file, if I have access to the raw file. As I ask here (webapps.stackexchange.com/questions/34066/…), there used to be an xml with all tweets, but no more. The rss feed has a limited time range and I couldn't find how to download, for example, all your tweets from the link you sent. Can you help? –  Strapakowsky Nov 3 '12 at 5:34
Apparently, you can only access tweets of up to 9 days old. Anything older than that is not available through search or even through the API. –  jokerdino Nov 3 '12 at 6:39
Are you sure there is no way to get tweets older than 9 days? I opened a question here: webapps.stackexchange.com/questions/34070/… –  Strapakowsky Nov 3 '12 at 8:08
Going directly to the user's page allows you to keep scrolling down so that the javascript loads the next page without limits. Would that be exploitable to retrieve all tweets? –  Strapakowsky Nov 3 '12 at 8:10
This link says you can't fetch more than a week's old tweets using search API. And I am not sure about fetching tweets using JavaScript. From what I know, you can't read more than about 3000 tweets or so from the timeline. –  jokerdino Nov 3 '12 at 8:15
add comment

Your Answer


