Katy likes to get her hands on interesting data. Recently, it’s been Twitter data among other things. Here are the steps I recently followed to get Twurl working on her Windows laptop.
ruby --version
gem --version
gem install twurl
twurl authorize --consumer-key CONSUMER_KEY --consumer-secret CONSUMER_SECRET
twurl /1.1/statuses/home_timeline.json
Next, we can run some Twitter search queries. Here’s the search example tweaked a little so it actually works:
Notice how I’ve surrounded the URL with double quotes: this is necessary since the &
character has special meaning on most operating systems including Windows.
This command will generate a blob of JSON. You can save this to a file as follows:
This will create a file named nasa.json
. You can pretty-print this JSON to the command prompt using a little Ruby script as follows:
A roughly equivalent Python script might be:
Note that this only returns the first 15 tweets. Here’s a bigger Python script that will handle the pagination for you:
Done for now.
Content © 2024 Richard Cook. All rights reserved.