A simple to use, feature-rich, tested node module for fetching Tweets from the Twitter API.
npm install fetch-tweets --save
Create a new Twitter app here to get your consumer key and secret.
Include the following code in your file.
var FetchTweets = ; // Include the module// Specify Twitter keys (preferably in an external .gitignore'd file)var apiKeys =consumer_key : 'XXXXXXXXXXXXXXXXXXXXXXXXX'consumer_secret : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';// Create a new object and pass in keys and optional additional options (see below)var fetchTweets = apiKeys;
The above code: includes the fetch-tweets module, creates a new instance and passes in your Twitter API keys.
There are two methods of selecting Tweets by keyword, using Twitter search API.
There are a series query operators that can be used inside this string parameter, such as fetching Tweets containg multiple keywords. To view a list of query operators click here.
You can also search for Tweets by passing in a JSON object containing options set by the Twitter API. There is an extensive list of options such as dates, locations, languages and popularity. For example:
var options =q: 'banana'lang: 'en'result_type: 'popular'count: 5fetchTweets;
View the full list of what you can pass in as options here in the Twitter documentation
There are two options for how you'd like your results returned:
This is default, so you don't need to do anything different than above
Results will be returned in the following format:
If you would like the full results returned by the Twitter API, then you can specify the second parameter as false when creating the fetchTweets object:
var FetchTweets = ;var fetchTweets = apiKeys false;
You can view an example of the format of these results here, on the Twitter website
fetch-tweets uses Mocha, Chai, Sinon and Istanbul to form it's testing environment.
To run all tests:
Summary of test results will be outputed to the console, more detailed results are generated and saved in the reports directory
fetch-tweets uses gulp to prepare all the files
gulp build to build
gulp test to test
gulp To clean directory, build, test, and watch for changes rebuilding when a file is modified
MIT � Alicia Sykes