4.0.0 • Published 3 days ago

rettiwt-core v4.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 days ago

Rettiwt-Core

A library for generating requests for Twitter API

Prerequisites

  • NodeJS 20.x

Installation

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

Available Resources

Currently, generation of request configuration for the following resources/actions is supported:

  • Lists:

    • Details
    • Tweets
  • Media:

    • Upload
    • Video Stream
  • Spaces:

    • Details (by id)
  • Tweets:

    • Details
    • Like
    • Likers
    • Post
    • Retweet
    • Retweeters
    • Search
    • Unlike
    • Unpost
    • Unretweet
  • Users:

    • Details (by id)
    • Details (by username)
    • Follow
    • Followers
    • Following
    • Highlights
    • Likes
    • Media
    • Subscriptions
    • Tweets
    • Tweets and Replies
    • Unfollow

Getting started

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

1. Getting the request to fetch the details of a Twitter user

import { Request } from 'rettiwt-core';

const request = new Request().user.detailsByUsername(user_name);

Where,

  • user_name is the user name of the Twitter user whose details are to be fetched.

2. Getting the request to fetch the list of users who liked a given tweet

import { Request } from 'rettiwt-core';

const request = new Request().tweet.likers(tweet_id, count, cursor);

Where,

  • tweet_id is the 'rest_id' of the Tweet whose likes are to be fetched.
  • count is the number of likers to fetch.
  • cursor is the cursor to the batch of likers to fetch.

3. Getting the request to fetch tweets using a filter to get tweets from specific users and containing specific words

import { Request } from 'rettiwt-core';

const request = new Request().tweet.search(
	{
		fromUsers: ['user_name_1', 'user_name_2'],
		includeWords: ['word_1', 'word_2'],
	},
	count,
	cursor,
);

Where,

  • user_name_1, user_name_2, .......... are the different usernames whose tweets are requried.
  • word_1, word_2, ........... are the different words that must be in the tweets.
  • count is the number of tweets to fetch.
  • cursor is the cursor to the batch of tweets to fetch.

Apart from this, other filters are also available (see here).

4. Getting the request to create a simple text Tweet

import { Request } from 'rettiwt-core';

const request = new Request().tweet.post({ text: 'text_to_tweet' });

Where,

  • text_to_tweet is the text which you want to tweet.

5. Getting a request to upload a media for a Tweet

Uploading a media is a three step process. These three steps are:

  1. Initialization
  2. Upload
  3. Finalization

1. Initialization

import { Request } from 'rettiwt-core';

const request = new Request().media.initializeUpload(size);

Where,

  • size is the size (in bytes) of the media to be uploaded.

Sending this request allocates a media_id to the media to be uploaded, which will be used for successive steps.

2. Upload

import { Request } from 'rettiwt-core';

const request = new Request().media.appendUpload(media_id, media_path);

Where,

  • media_id is the ID allocated to the media by sending the previous request.
  • media_path is the path to the media to be uploaded.

Sending this request uploads the media file to Twitter.

Notes:

  • Instead of a path to a locally stored file, an ArrayBuffer containing the media can also be uploaded

3. Finalization

import { Request } from 'rettiwt-core';

const request = new Request().media.finalizeUpload(media_id);

Where,

  • media_id is the ID allocated to the media uploaded using the previous reqeust.

Sending this request finalizes the upload process of the media and makes the media ready to be included in Tweets, via the media's allocated ID.

6. Getting the request to create a Tweet having media content

import { Request } from 'rettiwt-core';

const request = new Request().tweet.post({
	text: 'text_to_tweet',
	media: [
		{
			id: 'id_1',
			tags: ['user_id_1', 'user_id_2', 'user_id_3'],
		},
		{
			id: 'id_2',
			tags: ['user_id_4', 'user_id_5', 'user_id_6'],
		},
	],
});

Where,

  • 'text_to_tweet' is the text which you want to tweet.
  • 'id_1', 'id_2', ... are the allocated 'media_id' of the uploaded media.
  • 'user_id_1', 'user_id_2', ... are the 'rest_id' of the users to be tagged in the media.

Authenticating Requests

In order to actually be able to send the generated requests, you need to authenticate them, by following the steps described here.

Next steps

After generating the respective request configuration, the same can be used to make HTTP requests in order to access that specific resource.

API Reference

For the complete API reference, go through the full documentation.

4.0.0

3 days ago

4.0.0-alpha.5

2 months ago

4.0.0-alpha.6

2 months ago

4.0.0-alpha.3

2 months ago

4.0.0-alpha.4

2 months ago

4.0.0-alpha.2

2 months ago

4.0.0-alpha.1

2 months ago

4.0.0-alpha.0

2 months ago

3.5.0-alpha.2

2 months ago

3.5.0-alpha.1

2 months ago

3.5.0-alpha.0

2 months ago

3.4.0

2 months ago

3.3.2

2 months ago

3.4.0-alpha.2

3 months ago

3.4.0-alpha.1

3 months ago

3.4.0-alpha.0

3 months ago

3.3.1

3 months ago

3.3.0

3 months ago

3.3.0-alpha.6

4 months ago

3.3.0-alpha.5

4 months ago

3.3.0-alpha.4

4 months ago

3.3.0-alpha.3

4 months ago

3.3.0-alpha.2

4 months ago

3.3.0-alpha.1

4 months ago

3.3.0-alpha.0

4 months ago

3.2.1-alpha.1

7 months ago

3.2.1-alpha.0

7 months ago

3.2.1

7 months ago

3.2.0-alpha.0

8 months ago

3.2.0-alpha.1

8 months ago

3.2.0-alpha.2

8 months ago

3.2.0-alpha.3

8 months ago

3.2.0

8 months ago

3.1.2

9 months ago

3.1.1

9 months ago

3.1.0

9 months ago

3.1.0-alpha.0

9 months ago

3.0.0

9 months ago

3.0.0-alpha.2

9 months ago

3.0.0-alpha.1

10 months ago

3.0.0-alpha.0

10 months ago

3.0.0-rc.2

10 months ago

3.0.0-rc.1

10 months ago

3.0.0-rc.0

10 months ago

2.5.2

10 months ago

2.5.1

10 months ago

2.5.0

10 months ago

2.4.0

10 months ago

2.3.0

10 months ago

2.2.2

10 months ago

2.2.1

10 months ago

2.2.0

10 months ago

2.1.0

10 months ago

2.0.0

10 months ago

1.1.0

10 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago