简体   繁体   English

Ruby on Rails超过Twitter API速率限制

[英]Twitter API Rate Limit Exceeded in Ruby on Rails

I'm trying to use the Twitter Gem for Ruby/Rails in order to check whether an account exists on Twitter with a certain username. 我正在尝试将Twitter Gem用于Ruby / Rails,以便检查Twitter上是否存在具有特定用户名的帐户。

The problem is that after about 15 username checks, the rate limit is said to be exceeded. 问题是,经过大约15个用户名检查后,据说速率已超出限制。 I understand that Twitter limits its API calls to ~15 every 15 minutes or so, but is there a way that I can check more than one usernames existence in a call? 我知道Twitter将其API调用每15分钟左右限制为15个左右,但是有没有办法检查一次调用中是否存在多个用户名?

Here is the code I am currently using to check the existence 这是我目前用来检查是否存在的代码

def twitter_user_exists?(handle)
    $client.user(handle)
    true
rescue Twitter::Error::NotFound
    false
end

This executes for every username I have returning true/false based on whether the user exists. 这将根据用户是否存在对我返回的每个用户名执行true / false。

Let me know if more information/code is needed. 让我知道是否需要更多信息/代码。 Thanks. 谢谢。

I took a look around the Twitter gem and didn't see any other calls that would allow multiple users. 我环顾了Twitter上的gem,没有看到任何允许多个用户的呼叫。

If some of the checks are being done multiple times, you could store the result of whether or not an account is valid in the database and then retrieve it from the database if it already exists. 如果多次进行某些检查,则可以将帐户是否有效的结果存储在数据库中,然后从数据库中检索它(如果已存在)。 This would only be an issue if a user changes their twitter name or removes their account which probably won't happen too often. 仅当用户更改其Twitter名称或删除其帐户(可能不会经常发生)时,这才是问题。

Another option is to try to request the HTML version of the Twitter profile and see if that 404s or not. 另一个选择是尝试请求Twitter配置文件的HTML版本,看看是否有404。 Though it is possible that Twitter will rate limit this or block you. 尽管Twitter可能会对此进行速率限制或阻止您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM