Skip to content

Instantly share code, notes, and snippets.

@rmcvey
Last active December 13, 2017 05:18
Show Gist options
  • Save rmcvey/7ee7306a5fc8379ac8559ef8847940ff to your computer and use it in GitHub Desktop.
Save rmcvey/7ee7306a5fc8379ac8559ef8847940ff to your computer and use it in GitHub Desktop.
Simple NodeJS Twitter Search API Proxy

Simple NodeJS Twitter API Proxy

Currently only supports the /search endpoint docs.

Setup

Install NodeJS if you haven't already Download Node

  1. Download zip of this gist
  2. unzip file and cd into directory
  3. install package dependencies (express and twit) by running: npm install
  4. edit index.js with your Twitter API token/secret/oauth/etc.
  5. start the server: npm start
  6. ...
  7. deploy to heroku
  8. profit!
var express = require('express')
var app = express()
var Twit = require('twit')
var port = process.env.PORT || 8080;
// enter relevant information here
var T = new Twit({
consumer_key: '...',
consumer_secret: '...',
access_token: '...',
access_token_secret: '...',
timeout_ms: 60*1000, // optional HTTP request timeout to apply to all requests.
})
app.get('/search', function(req, res) {
T.get('search/tweets', req.query, function(err, data) {
if (err) {
return res.status(500).json(err)
}
res.json(data)
})
})
app.listen(port, function() {
console.log("Application listening at http://localhost:"+port)
})
{
"name": "twitter-api-client",
"version": "1.0.0",
"description": "Simple NodeJS Twitter Search API Proxy",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "",
"license": "MIT",
"dependencies": {
"express": "^4.16.2",
"twit": "^2.2.9"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment