【发布时间】:2014-05-08 08:35:53
【问题描述】:
我正在尝试使用 twitter4j api 从 twitter api 检索数据。在检索数据一段时间后,我收到以下错误:
Exception in thread "main" 403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following).
message - User has been suspended.
code - 63
我得出的结论是,上述错误导致 twitter api 支持的调用受到限制。如何创建间隔以便等到可以从 twitter 获取数据?
例如我的代码如下:
Long l = Long.parseLong(list.get(index));
TwitterResponse response = twitter.getFollowersIDs(l);
RateLimitStatus status = response.getRateLimitStatus();
if (status.getRemaining() < 2) {
try {
System.out.println("status.getSecondsUntilReset()");
Thread.sleep(status.getSecondsUntilReset());
} catch (InterruptedException e) {
System.out.println(e);
}
}
User user = twitter.showUser((l));
//statuses = twitter.getUserTimeline(l);
JSONObject features = new JSONObject();
features.put("_id", l);
score = kloutScore(l);
我的新代码包含一个 if 语句,它检查 status.getRemaining() 是否接近于零,然后等待 15 分钟,这实际上是限制持续时间。但是我遇到了 TwitterResponse response = twitter.getFollowerIDs(l); 的问题我收到了消息:
Exception in thread "main" 429:Returned in API v1.1 when a request cannot be served due to the application's rate limit having been exhausted for the resource. See Rate Limiting in API v1.1.(https://dev.twitter.com/docs/rate-limiting/1.1)
message - Rate limit exceeded
【问题讨论】:
-
我的回答包括有关如何避免超出 Twitter 施加的速率限制的说明。但是,您使用的帐户已被 Twitter 暂停。您需要使用其他用户(至少在您当前使用的用户的暂停被解除之前)。