draftbit / twitter-lite

A tiny, full-featured, flexible client / server library for the Twitter API
https://npm.im/twitter-lite
MIT License
794 stars 96 forks source link

Does `twitter-lite` report the current status of rate limits, in order to get the count of the API requests remaining in the current time-window? #199

Open 0xtetus opened 2 years ago

0xtetus commented 2 years ago

I'm using twitter-lite to periodically check the "followers" of 4 Twitter accounts. I know there's a rate limit for this operation, and since I'm creating a bot that people can trigger I want to make sure I don't hit the rate limit.

So just looking for a way to find out the number of requests I have left in each time-window. Is there a way to calculate this with twitter-lite or does Twitter API even report this number?

I'm open to any other ways or suggestions to tackle this.

steven-t-h commented 1 year ago

@0xtetus don't know if you ever found out, but it looks like the post method returns _header that will contain the response headers:

/**
   * Send a POST request
   * @param {string} resource - endpoint, e.g. `users/lookup`
   * @param {object} body - POST parameters object.
   *   Will be encoded appropriately (JSON or urlencoded) based on the resource
   * @returns {Promise<object>} Promise resolving to the response from the Twitter API.
   *   The `_header` property will be set to the Response headers (useful for checking rate limits)
   */
  post(resource, body)
...

There's an x-rate-limit-remaining header returned that should have what you're looking for.