Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Next returns less results than the specified max results #567

Open
nf-developer opened this issue Feb 10, 2025 · 0 comments
Open

[bug] Next returns less results than the specified max results #567

nf-developer opened this issue Feb 10, 2025 · 0 comments

Comments

@nf-developer
Copy link

nf-developer commented Feb 10, 2025

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:

  1. Request client setup (login method, OAuth2 scopes if applicable...)
  2. Endpoint used or code example of what's happening wrong
  3. Error stack trace, and if possible, error content (err.toJSON() when err 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant