Twi-JS
Installation
npm install twi-js
Configuring Module
const Twitter = require("twi-js");
How to use
Main Module
try {
const twitter = new Twitter(search_keywords, bearer_token, pages, whole_search, options);
twitter.fetchData();
} catch (error) {
console.log(error);
}
Arguments
- search_keywords (required): List of all keywords, hashtags and users
- bearer_token (required): Beare token
- pages (required): Number of times you want to search
- whole_search (required): Pass true if user has generated whole search query else false
- options (optional): Options contains lot of filters
Options Argument
Options is an object which contains other objects and values. Options contains following properties:
- media_filters
- query_filters
- options
- include_entities
- count
- result_type
- lang
- until
- tweet_mode
- geocode
Above mentioned all are optional parameters. search_keywords, bearer_token and pages are only required parameters.
Parameters and Values
media_filters: {
links: boolean | undefined,
images: boolean | undefined,
videos: boolean | undefined
media: boolean | undefined // for both kind (Image and Video)
vine: boolean | undefined
}
query_filters: {
to: string | undefined, // pass twitter username
from: string | undefined, // pass twitter username
retweets: boolean | undefined,
replies: boolean | undefined,
verified: boolean | undefined
}
options: {
include_entities: boolean | undefined,
count: number | undefined,
result_type: string | undefined,
lang: string | undefined,
until: string | undefined, // Date format: YYYY-MM-DD
tweet_mode: string | undefined, // If value is passed it should be extended.
geocode: {
latitude: number,
longitude: number,
radius: number,
matric: string,
} // Object | undefined
}
Here, where undefined is mentioned it states that one can ignore that parameter.
How To
-
How to search for word group: To search google developers club, pass
'"google developers club"'
- Pass keywords wrapped around double quotes
- What signle quotes do is consider "google developers club" as a string
- Double quotes are for internal recognition of grouping
-
How to search for multiple words: To search tweets containing node and express
- If we want both hashtags:
node AND express
ornode express
- If we want any hashtag (or both):
node OR express
- If we want both hashtags:
-
How to search exclude word: To search tweets containing mongo and exclude mysql
- If we want to exclude word mysql pass:
mongo -mysql
- If we want to exclude word mysql pass:
-
How to search for multiple hashtags:
To search tweets containing #javascript and #webdev- If we want both hashtags:
#javascript AND #webdev
or#javascript #webdev
- If we want any hashtag (or both):
#javascript OR #webdev
- If we want both hashtags:
Note: If you write @username
in search_keywords it will give you tweets in which user was mentioned.
TODO
- [ ] Add More Filters
- [ ] Add Test
- [ ] Add Comments
- [ ] More Documentation
- [x] Base Upload
- [x] Some Filters
- [x] Basic Github Automation
- [x] Manual Testing
If you want to learn more about these filters and parameter you can read my Introduction to Twitter API blog or official Twitter API Documentation.