gem install twurl
twurl authorize --consumer-key CONSUMER_KEY --consumer-secret CONSUMER_SECRET
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.
All content © 2019 Richard Cook. All rights reserved.