3
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

twitter gemでrate_limit_statusを叩きたいけどないので実装

とりあえず実装

client = Twitter::REST::Client.new do |config|
  config.consumer_key        = "..."
  config.consumer_secret     = "..."
end
res = Twitter::REST::Request.new(client, :get, '/1.1/application/rate_limit_status.json').perform
#ex.
p res[:resources][:search][:'/search/tweets'][:remaining]

なぜ

twitter gemではrate_limit_statusをサポートしていない。
以前は実装されていたが4.0.0で削除された様子。

なんで削除されたのかよくわからんと思ったら同様の人がいて
「TooManyRequestsをrescueすればよくね?」ということらしい。

This feature has already been requested and rejected. Why do you need this method? Instead of checking your rate limit status, you could simply rescue Twitter::Error:TooManyRequests, as demonstrated on the wiki.
Why was Twitter::API#rate_limit_status removed? #430

そうは言っても制限超える前にアラート上げたいようなときもある。
が、プルリク送ったところできっとrejectされるしHashのままでもそんなに困らないAPIなのでTwitter::REST::Request使って自前でお手軽に。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
3
Help us understand the problem. What are the problem?