node-twitter-api-v2 icon indicating copy to clipboard operation
node-twitter-api-v2 copied to clipboard

[bug] Pagination not working (tweets.fetchNext() always retrieving same tweets).

Open epsilongithub opened this issue 2 years ago • 5 comments

Describe the bug I'm trying to get all the tweets since a date. I first use userTimeline() and recieve 100 tweets. Then, I try to fetch the next results, but function always returns the same results.

To Reproduce Please indicate all steps that lead to this bug:

  1. Request client setup (login method, OAuth2 scopes if applicable...) image
  2. I use the endpoint of timeline to get the tweets image
  3. After receiving the api response, I try to iterate but I always get the same tweets. image

Expected behavior What I expect is to receive all the tweets within the dates with the iteration.

Version

  • Node.js 16.17.0
  • Lib 1.12.9
  • OS Linux Debian Server 16.04

epsilongithub avatar Nov 15 '22 12:11 epsilongithub

Hi, Did you find a way to overcome this issue? I cannot reproduce on my side, can you check what is the complete result on the first call (JSON.stringify(tweets.data))?

alkihis avatar Dec 22 '22 15:12 alkihis

Hi, Did you find a way to overcome this issue? I cannot reproduce on my side, can you check what is the complete result on the first call (JSON.stringify(tweets.data))?

The solution was to make the api with my own hand hahahaha If I remember correctly, the problem was that it was not able to send the pagination with the request or else it was because the library itself was not able to pass you the new twetts.

epsilongithub avatar Dec 22 '22 16:12 epsilongithub

Ok, no problem :D Can I close the issue, so, if you moved to something else and I cannot repro?

alkihis avatar Dec 22 '22 16:12 alkihis

I found a solution. Just pass count like this await client.v1.searchUsers(searchQuery, { page: count }) and keep incrementing count on load more or something like that.

anianroid avatar Feb 12 '23 12:02 anianroid

@alkihis I have the same issue. It looks like the paginator doesn't update the page number in fetchNext. getNextQueryParams always returns page: 2 because this._queryParams.page is always 1.

Same with fetchLast.

The workaround it to use next() (which is awkward) or manually update the page number:

usersPaginator._queryParams = usersPaginator.getNextQueryParams();

uluhonolulu avatar Feb 26 '23 20:02 uluhonolulu