Class TweetService

Handles fetching of data related to tweets.

Hierarchy

Constructors

Properties

authProxyUrl?: URL

The URL to the proxy server to use for authentication.

Methods

  • Get the details of a tweet.

    Parameters

    • id: string

      The id of the target tweet.

    Returns Promise<Tweet>

    The details of a single tweet with the given tweet id.

    Example

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Fetching the details of the tweet with the id '12345678'
    rettiwt.tweet.details('12345678')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Favorite the tweet with the given id.

    Parameters

    • tweetId: string

      The id of the tweet to be favorited.

    Returns Promise<boolean>

    Whether favoriting was successful or not.

    Example

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Liking the Tweet with id '12345678'
    rettiwt.tweet.favorite('12345678')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Get the list of users who liked a tweet.

    Parameters

    • tweetId: string

      The rest id of the target tweet.

    • Optional count: number

      The number of favoriters to fetch, must be <= 100.

    • Optional cursor: string

      The cursor to the batch of favoriters to fetch.

    Returns Promise<CursoredData<User>>

    The list of users who liked the given tweet.

    Example

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Fetching the most recent 100 likers of the Tweet with id '12345678'
    rettiwt.tweet.favoriters('12345678')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Fetches the requested resource from Twitter and returns it after processing.

    Type Parameters

    • OutType extends User | Tweet

      The type of deserialized data returned.

    Parameters

    • resourceType: EResourceType

      The type of resource to fetch.

    • args: FetchArgs

      Resource specific arguments.

    Returns Promise<CursoredData<OutType>>

    The processed data requested from Twitter.

  • Get the tweets from the tweet list with the given id.

    Parameters

    • listId: string

      The id of list from where the tweets are to be fetched.

    • Optional count: number

      The number of tweets to fetch, must be <= 100.

    • Optional cursor: string

      The cursor to the batch of tweets to fetch.

    Returns Promise<CursoredData<Tweet>>

    The list tweets present in the given list.

    Example

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Fetching the most recent 100 tweets of the Twitter list with id '12345678'
    rettiwt.tweet.list('12345678')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });

    Remarks

    Due a bug in Twitter API, the count is ignored when no cursor is provided and defaults to 100.

  • Posts the requested resource to Twitter and returns the response.

    Parameters

    • resourceType: EResourceType

      The type of resource to post.

    • args: PostArgs

      Resource specific arguments.

    Returns Promise<boolean>

    Whether posting was successful or not.

  • Retweet the tweet with the given id.

    Parameters

    • tweetId: string

      The id of the tweet with the given id.

    Returns Promise<boolean>

    Whether retweeting was successful or not.

    Example

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Retweeting the Tweet with id '12345678'
    rettiwt.tweet.retweet('12345678')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Get the list of users who retweeted a tweet.

    Parameters

    • tweetId: string

      The rest id of the target tweet.

    • Optional count: number

      The number of retweeters to fetch, must be <= 100.

    • Optional cursor: string

      The cursor to the batch of retweeters to fetch.

    Returns Promise<CursoredData<User>>

    The list of users who retweeted the given tweet.

    Example

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Fetching the most recent 100 retweeters of the Tweet with id '12345678'
    rettiwt.tweet.retweeters('12345678')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Search for tweets using a query.

    Parameters

    • query: TweetFilter

      The query be used for searching the tweets.

    • Optional count: number

      The number of tweets to fetch, must be <= 20.

    • Optional cursor: string

      The cursor to the batch of tweets to fetch.

    Returns Promise<CursoredData<Tweet>>

    The list of tweets that match the given filter.

    Example

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Fetching the most recent 5 tweets from user 'user1'
    rettiwt.tweet.search({ fromUsers: ['user1'] }, 5)
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });

    Remarks

    For details about available filters, refer to TweetFilter

  • Stream tweets in pseudo real-time using a filter.

    Parameters

    • filter: TweetFilter

      The filter to be used for searching the tweets.

    • pollingInterval: number = 60000

      The interval in milliseconds to poll for new tweets. Default interval is 60000 ms.

    Returns AsyncGenerator<Tweet, any, unknown>

    An async generator that yields matching tweets as they are found.

    Example

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Streaming all upcoming tweets from user 'user1'
    (async () => {
    try {
    for await (const tweet of rettiwt.tweet.stream({ fromUsers: ['user1'] }, 1000)) {
    console.log(tweet.fullText);
    }
    }
    catch (err) {
    console.log(err);
    }
    })();
  • Post a tweet.

    Parameters

    • text: string

      The text to be posted, length must be <= 280 characters.

    • Optional media: TweetMediaArgs[]

      The list of media to post in the tweet, max number of media must be <= 4.

    • Optional replyTo: string

      The id of the tweet to which the reply is to be made.

    Returns Promise<boolean>

    Whether posting was successful or not.

    Example

    Posting a simple text

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Posting a tweet to twitter
    rettiwt.tweet.tweet('Hello World!')
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });

    Example

    Posting a tweet with an image

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Posting a tweet, containing an image called 'mountains.jpg', to twitter
    rettiwt.tweet.tweet('What a nice view!', [{ path: 'mountains.jpg' }])
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });

    Example

    Posting a reply to a tweet

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Posting a simple text reply, to a tweet with id "1234567890"
    rettiwt.tweet.tweet('Hello!', undefined, "1234567890")
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });

Generated using TypeDoc