bird-elephant icon indicating copy to clipboard operation
bird-elephant copied to clipboard

HTTP headers for Rate Limits

Open ghnp5 opened this issue 2 years ago • 1 comments

Hey!

When making requests to the Twitter API, they return headers as described here:

https://developer.twitter.com/en/docs/twitter-api/rate-limits

Note that the HTTP headers are contextual. When using application-only authentication, they indicate the rate limit for the application context. When using user-based authentication, they indicate the rate limit for that user context.
x-rate-limit-limit: the rate limit ceiling for that given endpoint
x-rate-limit-remaining: the number of requests left for the 15-minute window
x-rate-limit-reset: the remaining window before the rate limit resets, in UTC epoch seconds

From what I understand, it's not possible to get these headers using BirdElephant, is that correct?

Thank you very much 😊

ghnp5 avatar Nov 24 '22 23:11 ghnp5

I added a line to print $request->getHeaders() in Request.php, around line 110, and I see the headers there:

  ["x-rate-limit-limit"]=>900
  ["x-rate-limit-reset"]=>1669337889
  ["x-rate-limit-remaining"]=>899

It would definitely be useful to be able to access these, after we make a request to Twitter API :) Saving them to some private field and then some function like ->getLastCallHeaders().

Another suggestion is to rename $request to $response, just to be clear that what's returned into that variable is a Response :)

ghnp5 avatar Nov 25 '22 00:11 ghnp5