fforres / Rettiwt-API

An API that fetches data from Twitter for other services to use

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rettiwt-API

An API for fetching data from Twitter for free!

Prerequisites

  • NodeJS 18.14.2
  • A working Twitter account

Installation

  1. Initialize a new Node.JS project using the command npm init.
  2. Install the package either via npm or yarn:
    • For npm, use the command npm install --save rettiwt-api
    • For yarn, use the command yarn add rettiwt-api

Although the above process initializes a new project, that is, in fact, not necessary and you may add it to an existing Node.JS project and omit the first step altogether.

Getting started

  1. Generate credentials using rettiwt-auth package, by following these steps.
  2. Copy the value of the 'cookies' field from the generated credentials and store it somewhere safe. Let's call this our API_KEY.
  3. Create a new instance of Rettiwt, passing in the API key:
    const rettiwt = Rettiwt(API_KEY);
  4. Use the created Rettiwt instance to fetch data from Twitter.

Note: The API_KEY (cookie) that we generated, is a very sensitive information and provides all access to the Twitter account. Therefore, it is generally recommended to store it as an environment variable and use it from there.

Usage

The following examples may help you to get started using the library:

1. Getting the details of a target Twitter user

const { Rettiwt } = require('rettiwt-api');

// Creating a new Rettiwt instance using the API_KEY
const rettiwt = new Rettiwt(API_KEY);

// Fetching the details of the user whose username is <username>
rettiwt.user.details('<username>')
.then(details => {
	...
})
.catch(error => {
	...
});

2. Getting the list of tweets that match a given filter

const { Rettiwt } = require('rettiwt-api');

// Creating a new Rettiwt instance using the API_KEY
const rettiwt = new Rettiwt(API_KEY);

/**
 * Fetching the list of tweets that:
 * 	- are made by a user with username <username>,
 * 	- contain the words <word1> and <word2>
 */
rettiwt.tweet.search({
	fromUsers: ['<username>'],
	words: ['<word1>', '<word2>']
})
.then(data => {
	...
})
.catch(err => {
	...
});

3. Getting the next batch of data using a cursor

The previous example fetches the the list of tweets matching the given filter. Since no count is specified, in this case, a default of 20 such Tweets are fetched initially. The following example demonstrates how to use the cursor string obtained from the response object's next field, from the previous example, to fetch the next batch of tweets:

const { Rettiwt } = require('rettiwt-api');

// Creating a new Rettiwt instance using the API_KEY
const rettiwt = new Rettiwt(API_KEY);

/**
 * Fetching the list of tweets that:
 * 	- are made by a user with username <username>,
 * 	- contain the words <word1> and <word2>
 *
 * 'data' is the response object received in the previous example.
 */
rettiwt.tweet.search({
	fromUsers: ['<username>'],
	words: ['<word1>', '<word2>']
}, data.next.value)
.then(data => {
	...
})
.catch(err => {
	...
});

For more information regarding the different available filter options, please refer to TweetFilter.

Features

So far, the following operations are supported:

Tweets

Users

API Reference

The complete API reference can be found at this page.

Additional information

  • This API uses the cookies of a Twitter account to fetch data from Twitter and as such, there is always a chance (altough a measly one) of getting the account banned by Twitter algorithm.
  • From personal experience, not a single one of my accounts has ever been banned by using this library, and this is coming from someone who has been using his primary Twitter account to fetch large amounts of data from Twitter for over 1.5 years now, since the conception of this project.
  • There have been no reports of accounts getting banned, but you have been warned, even though the chances of getting banned is negligible, it is not zero!

About

An API that fetches data from Twitter for other services to use


Languages

Language:TypeScript 96.2%Language:JavaScript 3.8%