使用 ruby​​ 的 Twitter api 标头

发布于 2024-11-24 17:19:10 字数 531 浏览 4 评论 0原文

主要是为了获得即时速率限制(此处进行了解释 › https://dev.twitter.com /docs/rate-limiting#feature-limiting),以便以最干净的方式调用服务:在每个请求上,都可以通过 X-FeatureRateLimit-Limit, X-FeatureRateLimit-RemainingX-FeatureRateLimit-Reset 在响应标头中发送。

可以通过调用另一个端点(https://dev.twitter.com/docs/api/1/get/account/rate_limit_status)来获取这些信息,但是,在某些时候似乎会消耗您的配额,这使得它有点无关紧要。

我的问题是,不可能知道如何读取这些特定的标题...... 可能没那么难,但是,如果有人提供帮助,谢谢。

Mainly to get instant rate limitations (explained here › https://dev.twitter.com/docs/rate-limiting#feature-limiting), in order to call the service the cleanest way possible : on every request, it is possible to get those infos via the X-FeatureRateLimit-Limit, X-FeatureRateLimit-Remaining and X-FeatureRateLimit-Reset sent in the response header.

It is possible to get thse information by calling another endpoint (https://dev.twitter.com/docs/api/1/get/account/rate_limit_status), but well, at some point seems to consume your quota, wich makes it kind of irrelevant.

My problem is, impossible to get how to read those specific headers…
Might not be that hard, but, if any help by anyone, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨的味道风的声音 2024-12-01 17:19:10

您可以使用 twitter API 包装器 来处理 http 标头本身:

def initialize(message, http_headers)
  @http_headers = Hash[http_headers]
  super message
end

def ratelimit_reset
  Time.at(@http_headers.values_at('x-ratelimit-reset', 'X-RateLimit-Reset').detect{|value| value}.to_i)
end

def ratelimit_limit
  @http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect{|value| value}.to_i
end

def ratelimit_remaining
  @http_headers.values_at('x-ratelimit-remaining', 'X-RateLimit-Remaining').detect{|value| value}.to_i
end

you can use twitter API wrapper that handles http header itself:

def initialize(message, http_headers)
  @http_headers = Hash[http_headers]
  super message
end

def ratelimit_reset
  Time.at(@http_headers.values_at('x-ratelimit-reset', 'X-RateLimit-Reset').detect{|value| value}.to_i)
end

def ratelimit_limit
  @http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect{|value| value}.to_i
end

def ratelimit_remaining
  @http_headers.values_at('x-ratelimit-remaining', 'X-RateLimit-Remaining').detect{|value| value}.to_i
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文