Example usage for twitter4j User getRateLimitStatus

List of usage examples for twitter4j User getRateLimitStatus

Introduction

In this page you can find the example usage for twitter4j User getRateLimitStatus.

Prototype

RateLimitStatus getRateLimitStatus();

Source Link

Document

Returns the current rate limit status if available.

Usage

From source file:org.loklak.harvester.TwitterAPI.java

License:Open Source License

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;
                }//from   ww w. ja  v  a2s. co m
            }
        }
    }
    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;
}

From source file:org.xmlsh.twitter.util.TwitterWriter.java

License:BSD License

private void write(String localName, User user) throws XMLStreamException {
    startElement("user");
    attribute("created-at", user.getCreatedAt());
    attribute("description", user.getDescription());
    attribute("favorites-count", user.getFavouritesCount());
    user.getFollowersCount();/* w w  w. j  ava  2s .c o  m*/
    user.getFriendsCount();
    attribute("id", sanitizeID(user.getId()));
    attribute("lang", user.getLang());
    user.getListedCount();

    attribute("name", sanitizeUser(user.getName()));
    user.getProfileBackgroundColor();
    user.getProfileBackgroundImageUrl();
    user.getProfileBackgroundImageUrlHttps();
    user.getProfileImageURL();
    user.getProfileImageUrlHttps();
    user.getProfileLinkColor();
    user.getProfileSidebarBorderColor();
    user.getProfileTextColor();
    user.getRateLimitStatus();
    attribute("screen-name", sanitizeUser(user.getScreenName()));

    user.getStatusesCount();
    user.getTimeZone();
    user.getURL();
    user.getUtcOffset();
    write("location", user.getLocation());
    write("user-status", user.getStatus());
    endElement();

}

From source file:twitterNetwork.extractUser.java

/*****token*/
public void dataextraction(ArrayList userName, int k, int l) {

    /*****///from  w  w  w .  j  a v a 2s .  c o m
    ConfigurationBuilder cb1 = new ConfigurationBuilder();
    cb1.setOAuthConsumerKey(consumerKey1);
    cb1.setOAuthConsumerSecret(consumerSecret1);
    cb1.setOAuthAccessToken(twitterToken1);
    cb1.setOAuthAccessTokenSecret(twitterSecret1);
    ConfigurationBuilder cb2 = new ConfigurationBuilder();
    cb2.setOAuthConsumerKey(consumerKey2);
    cb2.setOAuthConsumerSecret(consumerSecret2);
    cb2.setOAuthAccessToken(twitterToken2);
    cb2.setOAuthAccessTokenSecret(twitterSecret2);
    ConfigurationBuilder cb3 = new ConfigurationBuilder();
    cb3.setOAuthConsumerKey(consumerKey3);
    cb3.setOAuthConsumerSecret(consumerSecret3);
    cb3.setOAuthAccessToken(twitterToken3);
    cb3.setOAuthAccessTokenSecret(twitterSecret3);

    Twitter twitter1 = new TwitterFactory(cb1.build()).getInstance();
    Twitter twitter2 = new TwitterFactory(cb2.build()).getInstance();
    Twitter twitter3 = new TwitterFactory(cb3.build()).getInstance();

    ConfigurationBuilder cb4 = new ConfigurationBuilder();
    cb4.setOAuthConsumerKey(consumerKey4);
    cb4.setOAuthConsumerSecret(consumerSecret4);
    cb4.setOAuthAccessToken(twitterToken4);
    cb4.setOAuthAccessTokenSecret(twitterSecret4);
    ConfigurationBuilder cb5 = new ConfigurationBuilder();
    cb5.setOAuthConsumerKey(consumerKey5);
    cb5.setOAuthConsumerSecret(consumerSecret5);
    cb5.setOAuthAccessToken(twitterToken5);
    cb5.setOAuthAccessTokenSecret(twitterSecret5);
    ConfigurationBuilder cb6 = new ConfigurationBuilder();
    cb6.setOAuthConsumerKey(consumerKey6);
    cb6.setOAuthConsumerSecret(consumerSecret6);
    cb6.setOAuthAccessToken(twitterToken6);
    cb6.setOAuthAccessTokenSecret(twitterSecret6);
    ConfigurationBuilder cb7 = new ConfigurationBuilder();
    cb7.setOAuthConsumerKey(consumerKey7);
    cb7.setOAuthConsumerSecret(consumerSecret7);
    cb7.setOAuthAccessToken(twitterToken7);
    cb7.setOAuthAccessTokenSecret(twitterSecret7);
    ConfigurationBuilder cb8 = new ConfigurationBuilder();
    cb8.setOAuthConsumerKey(consumerKey8);
    cb8.setOAuthConsumerSecret(consumerSecret8);
    cb8.setOAuthAccessToken(twitterToken8);
    cb8.setOAuthAccessTokenSecret(twitterSecret8);
    Twitter twitter4 = new TwitterFactory(cb4.build()).getInstance();
    Twitter twitter5 = new TwitterFactory(cb5.build()).getInstance();
    Twitter twitter6 = new TwitterFactory(cb6.build()).getInstance();
    Twitter twitter7 = new TwitterFactory(cb7.build()).getInstance();
    Twitter twitter8 = new TwitterFactory(cb8.build()).getInstance();

    System.out.println("k" + k + "l" + l);
    int j = k;
    Follower obj = new Follower();
    User user1 = null;
    while (j < userName.size()) {
        try {
            // System.out.println(userName.get(j));
            int name = Integer.parseInt(userName.get(j).toString());
            if (l == 1) {
                user1 = twitter7.showUser(name);
            } else if (l == 2) {
                user1 = twitter2.showUser(name);
            } else if (l == 3) {
                user1 = twitter3.showUser(name);
            } else if (l == 4) {
                user1 = twitter4.showUser(name);
            } else if (l == 5) {
                user1 = twitter5.showUser(name);
            } else if (l == 6) {
                user1 = twitter6.showUser(name);
            } else if (l == 7) {
                user1 = twitter1.showUser(name);

            } else if (l == 8) {
                user1 = twitter8.showUser(name);
            } else {
                l = 1;
                dataextraction(userName, j, l);
            }

            //System.out.println(userName.get(j)+"---"+j);
            if (user1.getRateLimitStatus().getRemaining() > 2) {
                System.out.println(userName.get(j) + "," + user1.getScreenName());
            } else {

                System.out.println("rate2");
                //System.out.println(l+1+"---"+j);
                int m = l + 1;
                if (m == 9) {
                    m = 1;
                }
                dataextraction(userName, j, m);

            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        j++;
    }

}