Installing
You can install the tweets.js package using the following command
npm i tweets.js
support
usage
Getting the token
- Create an app on https://apps.twitter.com/
- Grab the Consumer Key (API Key) and Consumer Secret (API Secret) from Keys and Access Tokens
- Make sure you set the right access level for your app
- If you want to use user-based authentication, grab the access token key and secret as well
Using the package is pretty easy
setting up
const { client }= require('tweets.js');
const bot = new tweet({
consumer_key: "",
consumer_secret: "",
access_token: "",
access_token_secret: ""
});
Example
tweeting
bot.tweet('hello from tweets.js').then(console.log).catch(console.error)
Streams
-
Using the default settings
-
A stream emitter is ready on startup by default, you will just have to call <client>.start(parameters)
for it to be activated
-
Do not use all the events in the below code without knowing what they are for, only use ones you need
const parameters = {
follow: "1238451949000888322",
};
const stream = bot.start(parameters);
stream.on('ready', (res) => {
console.log('Stream ready');
});
stream.on("tweet", tweet => console.log(tweet));
stream.on('tweetDelete', (deletedTweet) => console.log(deletedTweet));
stream.on('raw', (data, type) => console.log('[', type, ']', '-', data));
stream.on('error', (err) => console.log(err));
stream.on("ping", () => console.log("ping"))
stream.on("end", () => console.log(`Stream ended`))
stream.on('reconnect', () => console.log('Reconnecting.....'));
stream.on('debug', (message) => console.log(message));
search for users
bot.searchUsers('typicalNinja').catch(console.log).then(users => {
console.log(users[0].id);
});
find all the methods in our docs here
Errors
Read-only application cannot POST
If you receive a error like above, change the permission for you app from dev portal to read and write
from read
- Make sure to reset your access Token and Secret
- it should be equal to below image
New version is here!!!
- supports streams
- Updated code
Credit