twitterApiWrapper

Learning to use the twitter REST and Streaming API

Usage no npm install needed!

<script type="module">
  import twitterApiWrapper from 'https://cdn.skypack.dev/twitterApiWrapper';
</script>

README

travis build of twitterApiWrapper david dependencies check of twitterApiWrapper semantic-release commitizen friendly npm version

twitterApiWrapper

A wrapper for the twitter REST and Streaming APIs for simplifying the calls and provide extended log outputs.

Using twitter can be quite difficult as you always need to look into the documentation in order to know how to perform queries. In comparison to the twitter module it relays on, the twitterApiWrapper does not require to know the query parameter's structure. The provided methods are easy to understand and simplify things a lot. Even if this wrapper may suit many users that want to perform simple queries, using the twitter API directly remains the recommended way to proceed. Using the query parameters of the Twitter API gives you full power on what should be retrieved, so, think about it before using this module. Have fun!

Installation

$ npm install --save twitterApiWrapper

Usage

var twitterApiWrapper = require('twitterApiWrapper');
var StreamApi = twitterApiWrapper.StreamApi;
var RestApi = twitterApiWrapper.RestApi;
// OR
import { StreamApi, RestApi } from 'twitterApiWrapper';

// Then
var twitterConfig = {
    'consumer_key': CHANGE_ME,
    'consumer_secret': CHANGE_ME,
    'access_token_key': CHANGE_ME,
    'access_token_secret': CHANGE_ME
};
var myStreamApi = new StreamApi(twitterConfig);
var myRestApi = new RestApi(twitterConfig);

// REST Api
myRestApi.getUserTimeline('BarackObama')
    .then((tweets) => { /*...*/ })
    .catch((err) => { /*...*/ });

// Streaming Api
myStreamApi.streamStatusesByKeyword(
    '#obama,#madonna',
    (tweet) => { /*...*/ },
    (err) => { /*...*/ }
);

API

REST API

getUserTimeline(username:String):Promise

Retrieves the tweets of the given user's timeline

Streaming API

streamStatusesByKeyword(keyword(s):String, onData:function, onError:function):stream

Retrieves the tweets of the given user's timeline

That's all?!

Yes, for now. The idea is to provide step by step well tested methods that are intuitive to use. Please feel free to contribute!

License