gpt4 book ai didi

java - Twitter4j - 超出速率限制

转载 作者:搜寻专家 更新时间:2023-10-31 08:19:57 24 4
gpt4 key购买 nike

我想在 Twitter4j 中使用 getFollowersIds() 获得关注者,但我得到了

ConnectionErrorException ... rate limit exceeded

public static void main(String[] args) {
try {
Twitter twitter = TwitterFactory.getSingleton();
String[] srch = new String[]{"TechCrunch"};
ResponseList<User> users = twitter.lookupUsers(srch);
for (User user : users) {

UserHarvest us = new UserHarvest(6017542);
us.getFollowersIds();
try {
us.getContributors();
} catch (ConnectionErrorException ex) {
Logger.getLogger(UserHarvest.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (TwitterException ex) {
Logger.getLogger(UserHarvest.class.getName()).log(Level.SEVERE, null, ex);
}
}

错误信息:

Exception in thread "main" harvest.twitterharvest.ConnectionErrorException: Connection could not have been established
at harvest.twitterharvest.WrapperTwitter4J.getFollowersIDs(WrapperTwitter4J.java:75)
at harvest.twitterharvest.UserHarvest.getFollowersIds(UserHarvest.java:106)
at harvest.twitterharvest.UserHarvest.main(UserHarvest.java:140)
Caused by: 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
code - 88

Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=92c30ec6 or
http://www.google.co.jp/search?q=19e1da11
TwitterException{exceptionCode=[92c30ec6-19e1da11], statusCode=429, message=Rate limit exceeded, code=88, retryAfter=-1, rateLimitStatus=RateLimitStatusJSONImpl{remaining=0, limit=15, resetTimeInSeconds=1384512813, secondsUntilReset=904}, version=3.0.4}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:162)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:89)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1894)
at twitter4j.TwitterImpl.getFollowersIDs(TwitterImpl.java:409)
at harvest.twitterharvest.WrapperTwitter4J.getFollowersIDs(WrapperTwitter4J.java:73)
... 2 more

我看到 secondsUntilReset=904。我在 1 小时后运行代码并收到相同的错误消息。我不知道为什么。感谢您的帮助。

最佳答案

Twitter API 中存在速率限制。您每 15 分钟调用给定 Twitter API 端点的次数不能超过给定次数(无论是否代表经过身份验证的用户)。

发生在你身上的是你的代码一定很快达到了速率限制(the endpoint to retrieve followers IDs 对于给定的经过身份验证的用户,每 15 分钟被限制为 15 次调用)所以你必须等待(904 秒)才能再次尝试.

请注意您正在调用(通过 Twitter4J)的 Twitter API 端点,以节省您的 API 调用,从而避免达到速率限制。

有关更多信息,请查看 Twitter Developers 上的那些资源, 特别是在 its documentation :

关于java - Twitter4j - 超出速率限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19999779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com