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

how best can we make the rate limiting information that twitter puts into the response headers available to the user? #11

Open
db48x opened this issue Aug 9, 2022 · 0 comments

Comments

@db48x
Copy link

db48x commented Aug 9, 2022

Twitter puts some information about your account’s rate limits in the response headers of every request. Most important is the time at which your rate limit is reset after a 429 response. See the documentation at https://developer.twitter.com/en/docs/twitter-api/rate-limits for all of the details.

I would like there to be some way to access this information, so that I can act on it. As a quick test, I tried sticking it on to the ApiError struct:

ApiError { title: "Too Many Requests", kind: "about:blank", status: 429, detail: "Too Many Requests", errors: [], reset: Some(1660051376) }

I added the simplest possible thing to api_error_for_status in api_result.rs:

let reset = self.headers().get("x-rate-limit-reset")
  .map(|v| v.to_str().unwrap().parse().unwrap());

and then added the resulting value to the ApiError that it creates.

This works, but it is not very elegant. It leaves two of the headers unavailable, and it would be rather nicer if it created a std::time::Duration for me, though that might be going a bit far. It also doesn’t do anything to make this information available on successful requests.

Do you prefer any particular way of implementing this?

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