Git Product home page Git Product logo

tweetserver's Introduction

TweetServer

TweetServer is a simple Node.js app for querying and caching responses from the Twitter REST API (version 1.1). It runs as a standalone server (built on Express) and effectively proxies any requests over to the API.

Why should you use it?

  • It handles the Twitter API rate limits for you, ensuring that the returned data is as up-to-date as possible without getting your application blacklisted for making too many requests.

  • It means you can communicate with the API from your front-end JavaScript with AJAX. This is difficult with the latest (1.1) version of the API since almost all requests have to be authenticated.

  • You can use it to display Tweets in your own style, rather than having to use one of the pre-built Twitter widgets.

  • Supports JSONP so you should be able to run your server anywhere and still make AJAX requests to it.

Setup

TweetServer is available as through npm. That's the recommended method of installation. Just install it as a global module:

npm install -g tweetserver

Configuration

TweetServer assumes you already have a Twitter application. If you don't, you can easily create one.

You'll need various credentials from Twitter to setup your Tweet Server. They can be found on the details page for the Twitter application you want to use. Sign in at the URL linked to above and make a note of your consumer key, consumer secret, access token and access token secret.

TweetServer will look for a configuration file on startup. Create a file named .tweetserverrc in your home directory, or the directory to which TweetServer was installed (any of the parent directories, including the root directory, will work too).

The .tweetserverrc file contains simple JSON in the following format:

{
    "port": 1234,
    "auth": {
        "accessToken": "xxxxx",
        "accessSecret": "xxxxx",
        "consumerKey": "xxxxx",
        "consumerSecret": "xxxxx"
    }
}

If you'd prefer not to store your API keys in a file, you can also specify them at startup with the following command line arguments:

Short option Long option Value
-k --access-token Your Twitter API access token
-a --access-secret Your Twitter API access token secret
-c --consumer-key Your Twitter API consumer key
-s --consumer-secret Your Twitter API consumer secret
-p --port The port on which the server will run

If you specify command line arguments and have a configuration file, the command line arguments will override the configuration file. You can run the server with any number of the arguments.

Running the server

If you installed TweetServer via npm with the -g (global) option, you will have a tweetserver command available to you. Just run that from anywhere (optionally with any of the command line arguments detailed above) to start the server:

tweetserver

You will see a message that tells you the server is now running. At this point you'll be able to open a browser and check that everything's working properly. Assuming your Tweet Server is running on localhost on port 3456 (which is the default), you can visit:

http://localhost:3456/statuses/user_timeline?screen_name=james_allardice

If you've used the Twitter API much before, you may have noticed that everything after the port in that URL is simply the same as what you would usually use when calling the API directly. Currently, all Twitter API v1.1 methods that support HTTP GET requests are supported.

Keeping the server running

I highly recommend using the brilliant "forever" module to keep your server up and running all the time.

tweetserver's People

Contributors

pmark avatar

Watchers

Jonathan Derrough avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.