A easy to use twitter api client
Tweets.ts is a continuation of project Tweets.js, rewritten in typescript, from now on, use tweets.ts instead of tweets.js (tweets.js will be deprecated in favour of this)
Install
npm i tweets.ts
Usage
Typescript
RestClient
import { Client } from 'tweets.ts';
const client = new Client({
authorization: {
consumer_key: 'Your Consumer Key',
consumer_secret: 'Your Consumer Secret',
access_token: 'Your access Token',
access_token_secret: 'Your Access Token Secret',
}
});
client.getFollowers('typicalninja69', { count: 20 }).then(res => console.log('Here is typicalninja\'s Followers', res)).catch(err => console.log('error occurred', err));
StreamClient
import { StreamClient, Tweet } from 'tweets.ts'
import { StreamClient, Client, Tweet } from 'tweets.ts'
const client = new Client({
authorization: {
consumer_key: 'Your Consumer Key',
consumer_secret: 'Your Consumer Secret',
access_token: 'Your access Token',
access_token_secret: 'Your Access Token Secret',
}
});
const streamClient = new StreamClient(client)
streamClient.stream({ endPoint: '/statuses/filter', body: { follow: "1238451949000888322", } });
streamClient.on('connected', () => {
console.log('Stream Client is now Connected')
});
streamClient.on('end', (reason: string) => {
console.log('Stream Ended due to:', reason)
});
streamClient.on('tweet', (tweet: Tweet) => {
console.log('New Tweet:')
console.log(tweet)
});
setTimeout(() => {
streamClient.end('Time ended, we don\'t need a stream now');
}, 10000)
JavaScript
RestClient
const { Client } = require('tweets.ts');
const client = new Client({
authorization: {
consumer_key: 'Your Consumer Key',
consumer_secret: 'Your Consumer Secret',
access_token: 'Your access Token',
access_token_secret: 'Your Access Token Secret',
}
});
client.getFollowers('typicalninja69', { count: 20 }).then(res => console.log('Here is typicalninja\'s Followers', res)).catch(err => console.log('error occurred', err));
StreamClient
const { StreamClient } = require('tweets.ts');
const { StreamClient, Client } = require('tweets.ts')
const client = new Client({
authorization: {
consumer_key: 'Your Consumer Key',
consumer_secret: 'Your Consumer Secret',
access_token: 'Your access Token',
access_token_secret: 'Your Access Token Secret',
}
});
const streamClient = new StreamClient(client)
streamClient.stream({ endPoint: '/statuses/filter', body: { follow: "1238451949000888322", } });
streamClient.on('connected', () => {
console.log('Stream Client is now Connected')
});
streamClient.on('end', (reason) => {
console.log('Stream Ended due to:', reason)
});
streamClient.on('tweet', (tweet) => {
console.log('New Tweet:')
console.log(tweet)
});
setTimeout(() => {
streamClient.end('Time ended, we don\'t need a stream now');
}, 10000)
Using the raw Api
Raw api is querying the api using builtin methods like post(), get(), you completely controls these methods. so least support is given for usage of this
client is a instance of tweet.ts client
Get
const request = await client.get({ endPoint: '/endPoint/here/:id', bodyOrParams: { id: 'this will be in the endpoint param', someOtherParam: 'follow' } })
console.log(request);
Post
const request = await client.post({ endPoint: '/endPoint/here/to/post/:id', bodyOrParams: { id: 'this will be in the endpoint param', someOtherBody: 'this will be in the body' } })
console.log(request);
FAQ
- How Do i get Authorization credential's
See this url : Click here
- How can i use bearer token (app authentication)
Sadly you cant, in typescript rewrite (tweets.ts) App authentication support was removed, You can use another library like this one for app authentication purpose
You can use our Discord server to get support, join here
Author
👤 typicalninja21
Show your support
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator