Open
Description
Describe the bug
As a developer I want to search all posts by calling next(500)
and either receive 500 posts or 0 posts if the rate limit is reached.
Issue: I am getting <500 posts unexpectedly.
To Reproduce
Please indicate all steps that lead to this bug:
- Request client setup (login method, OAuth2 scopes if applicable...)
- Endpoint used or code example of what's happening wrong
- Error stack trace, and if possible, error content (
err.toJSON()
whenerr
is the caught error; take care of removing authentication HTTP headers)
const xAPI = new TwitterApi({
appKey: '...',
appSecret: '...'
})
const client = (await xAPI.appLogin()).readOnly.v2
let processed = 0
let searchResults = null
while (processed < 10000) {
searchResults = !searchResults ?
await xClient.searchAll(query, {
"max_results":500,
"expansions":["attachments.media_keys"],
"tweet.fields":["created_at","public_metrics"],
"media.fields":["media_key","type","url","duration_ms","preview_image_url","variants"],
"start_time":"2006-12-31T00:00:00.000Z",
"end_time":"2025-01-01T09:59:59.999Z"
}) :
await searchResults.next(Math.min(500, 10000 - processed))
console.log(searchResults.data.data)
processed += searchResults.data.data.length
}
Expected behavior
A clear and concise description of what you expected to happen.
The console.log
should output 20 lines where each line contains 500 posts.
Expected number of posts | Actual |
---|---|
500 | 500 |
500 | 498 |
500 | 499 |
500 | 498 |
500 | 496 |
500 | 495 |
500 | 497 |
500 | 498 |
500 | 487 |
500 | 485 |
500 | 498 |
500 | 493 |
500 | 489 |
500 | 496 |
500 | 495 |
500 | 498 |
500 | 493 |
500 | 495 |
500 | 494 |
500 | 497 |
99 | 497 |
Version
- Node.js version
- Lib version
- OS (especially if you use Windows)
Name | Version |
---|---|
node -v | v20.18.1 |
Lib version | ^1.19.1 |
OS | Mac OS |
Additional context
N/A
Metadata
Metadata
Assignees
Labels
No labels