It runs as a Node.js app, currently hosted on Heroku. Feel free to fork and host your own version wherever suits you.
Clone the app to a local directory. You'll need to register a new application with Twitter. Once registered, create a file called
.env to store your app details for local testing. It should contain the following (replace the XXX with your details):
consumer_key=XXX consumer_secret=XXX access_token_key=XXX access_token_secret=XXX
Caching: Redis Cloud
Since Twitter imposes quite strict usage limits, the app stores requests in Redis with a 15 minute expiry. Since I've deployed this to Heroku, I've added support for Redis Cloud. If using Heroku, activating Redis Cloud (currently with a 20MB free plan) will automatically work.
Running the app
Ensure you have Node.js installed. Install any dependencies first:
$ npm install
Then run the app:
$ node app
If you have
foreman installed, run the app like so:
$ foreman start
Since I wanted it to work with Heroku, the app runs by default on port
Currently the app will return a 404 unless the path contains either
Search is as follows:
This will search Twitter for the phrase "foo" and return a JSON response containing the results. You can create more complex queries:
The search in this case will be "this AND that".
Adding a URL into the path won't work as the app splits the URL parts by
/. To get around this, you can structure a request like this to search for a specific URL:
I have deployed it to Heroku using these instructions. Since it's a light, database-free app, it could just as well live on a free Appfog instance also.
You'll need to add the environment variables listed above when setting up your app with Heroku etc.
This app relies on ntwitter.
Some tests would be a good idea. I threw this implementation together in a morning as a proof of concept, so before doing any more work on it I'll get some unit tests in place.
MIT license applied. Have fun. Pull requests and improvements much appreciated.