I'm working with the twitter-api-v2 library in conjunction with the @twitter-api-v2/plugin-rate-limit plugin for Node.js. I'm facing two main issues:
- When I attempt to fetch the rate limit for the 'users/me' endpoint using the plugin, it returns undefined.
const rateLimitStatus = await rateLimitPlugin.v2.getRateLimit('users/me');
console.log('Rate Limit Status:', rateLimitStatus);
- When I try to post a tweet using twitterClient.v2.tweet(tweetText), even though I still have a large number of requests remaining (39999 out of 40000), the plugin indicates that I've hit the rate limit:
[2023.08.14-08.34.14.0642] Rate limit exceeded when replying to tweet. Limit: 40000 Remaining: 39999 Last reset: 14/08/2023, 08:49:14
This is confusing as I'd expect to hit the rate limit only when the remaining count reaches 0.
Here's a relevant snippet of my code:
import { TwitterApi } from "twitter-api-v2";
import { TwitterApiRateLimitPlugin } from '@twitter-api-v2/plugin-rate-limit';
const rateLimitPlugin = new TwitterApiRateLimitPlugin();
// ... (TwitterApi configuration)
export const postTweet = async (tweetText) => {
try {
const rateLimitStatus = await rateLimitPlugin.v2.getRateLimit('users/me');
console.log('Rate Limit Status:', rateLimitStatus);
if (rateLimitStatus?.remaining <= 40000) {
// ... (wait logic)
}
const response = await twitterClient.v2.tweet(tweetText);
// ... (Logging and handling the response)
} catch (e) {
if (e.code === 429) {
// ... (Handling rate limit exceeded error)
} else {
// ... (Handling other errors)
}
}
};
Any insights on these issues would be greatly appreciated. Specifically:
Is there an updated endpoint string to check rate limits instead of 'users/me'? How do I interpret the rate limit data and why am I receiving an alert even though I haven't exhausted my limits? Thanks in advance!