A prototype of twitter restful API server, copied from @igorlima.
This repo is a public HTTP API to retrieve Twitter user timelines. It has basically two files: server.js and twitter.js.
The first file creates an basic instance of express and defines a route for a GET request method, which is /twitter/timeline/:user
.
The second one is a module responsible for retrieving data from Twitter. It requires:
- twit: Twitter API Client for node
- async: is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript
- moment: a lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.
Part of these modules will be mocked and overridden in our tests.
This example is already running in a cloud. So you can reach the urls below and see it working:
To run it locally, clone this gist by git clone https://gist.github.com/b31f1a26a5b100186a98.git twitter-rest-api-server
and set five environment variables. Those envs are listed below. For secure reason I won't share my token. To get yours, access Twitter developer documentation, create a new app and set up your credentials.
For Mac users, you can simply type:
export TwitterConsumerKey="xxxx"
export TwitterConsumerSecret="xxxx"
export TwitterAccessToken="xxxx"
export TwitterAccessTokenSecret="xxxx"
export MomentLang="pt-br"
For Windows users, do:
SET TwitterConsumerKey="xxxx"
SET TwitterConsumerSecret="xxxx"
SET TwitterAccessToken="xxxx"
SET TwitterAccessTokenSecret="xxxx"
SET MomentLang="pt-br"
After setting up the environment variables, go to twitter-rest-api-server
folder, install all node dependencies by npm install
, then run via terminal node server.js
. It should be available at the port 5000
. Go to your browser and reach http://localhost:5000/twitter/timeline/igorribeirolima
.