Twitter streaming API examples

Update 5/2014 – all of these examples are broken due to Twitter API upgrade that requires OAUTH instead of user/password. Have left this post – as an example of what you can do. For examples of alternatives, see the internet-sensors projects: https://github.com/tkzic/internet-sensors

— original post —

Here is an example that I actually got working to track mention of dogs… You need to replace USER:PASS with your Twitter login and password. The JSON search results will be written to the file tweets.json.

A running tally of results will be displayed to the console while this is running.

curl https://stream.twitter.com/1/statuses/filter.json -u USER:PASSWORD -d "track=dog" > tweets.json

This one searches for #cats (hashtag)

curl https://stream.twitter.com/1/statuses/filter.json -u USERNAME:PASSWORD -d "track=#cats" > tweets.json

https://dev.twitter.com/discussions/2403

Haven’t tried this one:

Do you have a specific example which doesn’t appear to work? Following Taylor’s advice, I was able to find several streaming entries tracking the “photo” keyword:

  1. curl https://stream.twitter.com/1/statuses/filter.json -d 'track=photo' -u [username]:[password] -# | grep "\"media_url\""

Here is a technique (in the answer) which tracks when the stream gets a hit

http://stackoverflow.com/questions/4786786/using-curl-to-update-mysql-when-curl-spits-out-json

Here are other useful links and examples:

basic curl statuses example, no filters

https://dev.twitter.com/discussions/9911

Look at the post from Matt Seward to do locations…

https://dev.twitter.com/discussions/3779

followers:

https://dev.twitter.com/discussions/4067

tracking:

https://dev.twitter.com/discussions/5520