4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

とりあえず実装

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使って自前でお手軽に。

4
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?