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

Iteration through paginated data #91

Open
1 task done
hubgit opened this issue Aug 13, 2021 · 2 comments
Open
1 task done

Iteration through paginated data #91

hubgit opened this issue Aug 13, 2021 · 2 comments

Comments

@hubgit
Copy link

hubgit commented Aug 13, 2021

Prerequisites

  • Put an X between the brackets on this line if you have done all of the
    following:
    • Checked this feature isn't already filed: [open features]
    • Checked the [feature request guidelines]

Summary

It would be helpful to be able to iterate through paginated data, via an async iterator.

Motivation

At the moment the user has to manually handle paginated responses by reading meta.next_token and setting it as params.pagination_token on a new request.

It would be helpful if it was possible to use for await (const item of client.get(path, params)) { … } (where item is an item from the data array in each response) to iterate through each item automatically.

Describe alternatives you've considered

Making requests in a do { … } while (params.pagination_token) loop.

@mdodge-ecgrow
Copy link

mdodge-ecgrow commented Sep 2, 2021

Not sure if this warrants a new issue or not. But I am trying to implement pagination to get all the 100+ replies in the conversation. I am getting the error: Error: Invalid Request: One or more parameters to your request was invalid.

Here is the code that is attempting to retrieve the replies:

const { data, meta } = await client.get("tweets/search/recent", {
      query: "conversation_id: " + id,
      "tweet.fields":
        "in_reply_to_user_id,author_id,created_at,conversation_id",
      max_results: 100,
      pagination_token: next_token,
    });

Also, that exact same code works perfect when I don't have the pagination_token parameter in there. So something is wonky with that parameter.

Also, I have verified that next_token is indeed the next_token from the previous query's meta object.

@hubgit
Copy link
Author

hubgit commented Sep 2, 2021

@mdodge-ecgrow For some reason the v2 tweets/search/recent endpoint seems to use next_token as the parameter name instead of pagination_token.

image

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

2 participants