RateLimitStatus rateStatus = ids.getRateLimitStatus(); if (networkRelation == Networker.FOLLOWERS) { getFollowerIdRemaining = rateStatus.getRemaining(); getFollowerIdResetTime = System.currentTimeMillis() + rateStatus.getSecondsUntilReset() * 1000; } else { getFollowingIdRemaining = rateStatus.getRemaining(); getFollowingIdResetTime = System.currentTimeMillis() + rateStatus.getSecondsUntilReset() * 1000; if (rateStatus.getRemaining() == 0) { complete = false; break collect;
Map<String ,RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus(); for (String endpoint : rateLimitStatus.keySet()) { RateLimitStatus status = rateLimitStatus.get(endpoint); System.out.println("Endpoint: " + endpoint); System.out.println(" Limit: " + status.getLimit()); System.out.println(" Remaining: " + status.getRemaining()); System.out.println(" ResetTimeInSeconds: " + status.getResetTimeInSeconds()); System.out.println(" SecondsUntilReset: " + status.getSecondsUntilReset()); }
RateLimitStatus rateLimitStatus = getRateLimitStatus(); if (rateLimitStatus != null) { retryAfter = rateLimitStatus.getSecondsUntilReset();
private void checkRateLimitStatus(final RateLimitStatus status, final WTFDYUMExceptionType exceptionType) throws WTFDYUMException { if (status.getRemaining() == 0) { throw new WTFDYUMException(exceptionType); } }
/* package */ RateLimitStatus(Response res) throws TwitterException { super(res); Element elem = res.asDocument().getDocumentElement(); remainingHits = getChildInt("remaining-hits", elem); hourlyLimit = getChildInt("hourly-limit", elem); resetTimeInSeconds = getChildInt("reset-time-in-seconds", elem); resetTime = getChildDate("reset-time", elem, "yyyy-M-d'T'HH:mm:ss+00:00"); }
/** * Returns the remaining number of API requests available to the requesting user before the API limit is reached for the current hour. Calls to rate_limit_status do not count against the rate limit. If authentication credentials are provided, the rate limit status for the authenticating user is returned. Otherwise, the rate limit status for the requester's IP address is returned.<br> * * @return the rate limit status * @throws TwitterException when Twitter service or network is unavailable * @since Twitter4J 1.1.4 * @see <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-account%C2%A0rate_limit_status">Twitter API Wiki / Twitter REST API Method: account rate_limit_status</a> */ public RateLimitStatus rateLimitStatus() throws TwitterException { return new RateLimitStatus(http.get(getBaseURL() + "account/rate_limit_status.xml", null != getUserId() && null != getPassword())); }
@Override public Tweet showStatus(Long id) throws TwitterApiException { try { Status status = twitter.showStatus(id); Tweet.Builder tweetBuilder = new Tweet.Builder() .body(status.getText()) .datePosted(new DateTime(status.getCreatedAt())) .id(id) .poster(status.getUser().getScreenName()); prepareEntities(status, tweetBuilder); return tweetBuilder.build(); } catch (TwitterException e) { throw new TwitterApiException(e, e.exceededRateLimitation(), (e.getRateLimitStatus() != null && e.getRateLimitStatus().getSecondsUntilReset() > 0) ? e.getRateLimitStatus().getSecondsUntilReset() * 1000 : 0, e.getErrorCode()); } }
public static JSONObject getUser(String screen_name, boolean forceReload) throws TwitterException, IOException { if (!forceReload) { JsonFactory mapcapsule = DAO.user_dump.get("screen_name",screen_name); if (mapcapsule == null) mapcapsule = DAO.user_dump.get("id_str", screen_name); if (mapcapsule != null) { JSONObject json = mapcapsule.getJSON(); if (json.length() > 0) { // check if the entry is maybe outdated, i.e. if it is empty or too old try { Date d = DAO.user_dump.parseDate(json); if (d.getTime() + DateParser.DAY_MILLIS > System.currentTimeMillis()) return json; } catch (ParseException e) { return json; } } } } TwitterFactory tf = getUserTwitterFactory(screen_name); if (tf == null) tf = getAppTwitterFactory(); if (tf == null) return new JSONObject(); Twitter twitter = tf.getInstance(); User user = twitter.showUser(screen_name); RateLimitStatus rateLimitStatus = user.getRateLimitStatus(); getUserResetTime = System.currentTimeMillis() + rateLimitStatus.getSecondsUntilReset() * 1000; getUserRemaining = rateLimitStatus.getRemaining(); JSONObject json = user2json(user); enrichLocation(json); DAO.user_dump.putUnique(json); return json; }
do { TwitterResponse response = twitter.getFollowersIDs(userId, cursor); RateLimitStatus status = response.getRateLimitStatus(); if(status.getRemaining() == 0) { try { Thread.sleep(status.getSecondsUntilReset() * 1000); } catch(InterruptedException e) { // ... } } } while(cursor > 0);