Giter VIP home page Giter VIP logo

tweets.ts's Introduction

Deprecated

Read

Welcome to tweets.ts ๐Ÿ‘‹

Version Documentation License: ISC Twitter: typicalninja69

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)

๐Ÿ  Homepage

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',
  }
});

//... do what ever you want, use tweets.axix.cf for docs
// this is a example

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'

// or...

import { StreamClient, Client, Tweet } from 'tweets.ts'



// if passing the whole client to streamClient (recommended)
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',
  }
});


// ... if passing whole Client to streamClient (recommended)
 const streamClient = new StreamClient(client)

/*
else....

 const streamClient = new StreamClient({
  authorization: {
    consumer_key: 'Your Consumer Key',
    consumer_secret: 'Your Consumer Secret',
    access_token: 'Your access Token',
    access_token_secret: 'Your Access Token Secret',
  }
 })
*/

// this is a must
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)
});

// to end this client
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',
  }
});

//... do what ever you want, use tweets.axix.cf for docs
// this is a example

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');

// or...
const { StreamClient, Client } = require('tweets.ts')

// if passing the whole client to streamClient (recommended)
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',
  }
});


// ... if passing whole Client to streamClient (recommended)
 const streamClient = new StreamClient(client)

/*
else....

 const streamClient = new StreamClient({
  authorization: {
    consumer_key: 'Your Consumer Key',
    consumer_secret: 'Your Consumer Secret',
    access_token: 'Your access Token',
    access_token_secret: 'Your Access Token Secret',
  }
 })
*/

// this is a must
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)
});

// to end this client
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

// returns a promise, must be inside a async function, unless you use .then

const request = await client.get({ endPoint: '/endPoint/here/:id', bodyOrParams: { id: 'this will be in the endpoint param', someOtherParam: 'follow' } })

// raw json data
console.log(request);

Post

// returns a promise, must be inside a async function, unless you use .then

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' } })

// raw json data
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

  • Where can i get support?

You can use our Discord server to get support, join here

Or you can use our github issue tracker, here

Due to me (typicalninja) Not being available A Github Issue is more convenient if you need support

License

This repository and the code inside it is licensed under the MIT License. Read LICENSE for more information.

Author

๐Ÿ‘ค typicalninja21

Show your support

Give a โญ๏ธ if this project helped you!


This README was generated with โค๏ธ by readme-md-generator

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.