Example usage for twitter4j TwitterFactory TwitterFactory

List of usage examples for twitter4j TwitterFactory TwitterFactory

Introduction

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

Prototype

public TwitterFactory(String configTreePath) 

Source Link

Document

Creates a TwitterFactory with a specified config tree

Usage

From source file:TwitterSend2.java

License:BEER-WARE LICENSE

public void twitterConfiguration() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey("2XYWWfo3BHdF17nVF6Nyg");
    cb.setOAuthConsumerSecret("XQtpXlLu8uJWgyI3XVEMHcCHCSwar9KbTnTWuXJmXk");
    cb.setOAuthAccessToken("613021275-Y3Utjpyh8cfAYpGel6UWs1aqzUMOdGuxuwsUc9jo");
    cb.setOAuthAccessTokenSecret("2NC2l6KgVVymgeNez9X2s0YezMhVXuO1UPq8j60IeI");
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();//from  w  w  w  . jav a2 s . co m
}

From source file:NewMain.java

/**
 * @param args the command line arguments
 *//*from   www.ja  v a 2s. c o  m*/

public static void main(String[] args) throws TwitterException {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();
    ResponseList<twitter4j.Status> statuses = twitter.getHomeTimeline();
    System.out.println("Mostrando el timeline...");
    for (twitter4j.Status status : statuses) {
        System.out.println("@" + status.getUser().getScreenName() + ": " + status.getText());

    }
}

From source file:GetHomePageData.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*  ww w  .  j  a v a 2 s . co  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try {
        /* TODO output your page here. You may use following sample code. */
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet GetHomePageData</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet GetHomePageData at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey("Olwk4ncLNgYZcROLvP9oAFrgv")
                .setOAuthConsumerSecret("eht2OHYflAV1Cu8GP9XA46zm7KbiivY35TytvJ91aMX67brKEF")
                .setOAuthAccessToken("1668200646-cR34ReTvqAUgQGNvFQWlbGNkGgksXvq7yFHWlO6")
                .setOAuthAccessTokenSecret("VAU21C4JHFCrbBfwDfTkdLEkSkpjBD7VFkFowFwLPAuoC");

        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();

        List<Status> statuses;
        //statuses= twitter.getHomeTimeline();
        out.println("Showing home timeline.");
        // for (Status status : statuses) 
        //   out.println(status.getUser().getName() + ":" +     status.getText());

    } catch (Exception e) {

    }
}

From source file:twitterGateway_v2_06.java

License:Creative Commons License

public void SetupTwitter() {
    //twitterIn = new TwitterConnectStream();
    //accessToken = new AccessToken(TwitterAccessToken, TwitterAccessTokenSecret);
    //TwitterOAuthAuthorization.setOAuthAccessToken(accessToken);
    //TwitterOAuthAuthorization = new OAuthAuthorization(conf);
    //TwitterOAuthAuthorization.setOAuthConsumer(TwitterConsumerKey, TwitterConsumerSecret);
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(TwitterConsumerKey)
            .setOAuthConsumerSecret(TwitterConsumerSecret).setOAuthAccessToken(TwitterAccessToken)
            .setOAuthAccessTokenSecret(TwitterAccessTokenSecret);
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitterOut = tf.getInstance();//www . j av a 2s . co m
    //  try {
    //  twitterOut.updateStatus("Hello World!");
    //  }
    //  catch (TwitterException ex) {
    //    println(ex);
    //  }
    ActivityLogAddLine("twitter connector ready");
    output = createWriter("log.txt");

    StatusListener twitterIn = new StatusListener() {
        public void onStatus(Status status) {
            double Longitude;
            double Latitude;
            GeoLocation GeoLoc = status.getGeoLocation();
            if (GeoLoc != null) {
                //println("YES got a location");
                Longitude = GeoLoc.getLongitude();
                Latitude = GeoLoc.getLatitude();
            } else {
                Longitude = 0;
                Latitude = 0;
            }
            println(TimeStamp() + "\t" + Latitude + "\t" + Longitude + "\t" + status.getUser().getScreenName()
                    + "\t" + status.getText());
            output.println(TimeStamp() + "\t" + Latitude + "\t" + Longitude + "\t"
                    + status.getUser().getScreenName() + "\t" + status.getText());
            output.flush();
            TwitterToOsc(status.getUser().getScreenName(), status.getText());
        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        public void onException(Exception ex) {
            println("CAUGHT in the ACT: " + ex);
        }
    };

    ConfigurationBuilder cbIn = new ConfigurationBuilder();
    cbIn.setDebugEnabled(true).setOAuthConsumerKey(TwitterConsumerKey)
            .setOAuthConsumerSecret(TwitterConsumerSecret).setOAuthAccessToken(TwitterAccessToken)
            .setOAuthAccessTokenSecret(TwitterAccessTokenSecret);

    TwitterStreamFactory ts = new TwitterStreamFactory(cbIn.build());
    TwitterStream twitterStream = ts.getInstance();
    twitterStream.addListener(twitterIn);

    // filter() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
    FilterQuery twitterFilter = new FilterQuery(0, TwitterFollowIDs, TwitterTrackWords);
    twitterStream.filter(twitterFilter);
}

From source file:TwitterRetrieval.java

License:Apache License

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out;//from  ww w.j  av a  2s.  co  m
    try {

        // img stuff not req'd for source code html showing
        // all links relative
        // XXX
        // making these absolute till we work out the
        // addition of a PathInfo issue

        ConfigurationBuilder cb = new ConfigurationBuilder();
        System.setProperty("twitter4j.http.httpClient", "twitter4j.internal.http.HttpClientImpl");
        cb.setOAuthConsumerKey("56NAE9lQHSOZIGXRktd5Qw")
                .setOAuthConsumerSecret("zJjJrUUs1ubwKjtPOyYzrwBJzpwq7ud8Aryq1VhYH2E")
                .setOAuthAccessTokenURL("https://api.twitter.com/oauth/access_token")
                .setOAuthRequestTokenURL("https://api.twitter.com/oauth/request_token")
                .setOAuthAuthorizationURL("https://api.twitter.com/oauth/authorize")
                .setOAuthAccessToken("234742739-I1l0VGTTjRUbZrfH1jvKnTVFU9ZEvkxxUDpvsAJ2")
                .setOAuthAccessTokenSecret("jLe3imI3JiPgmHCatt6SqYgRAcX5q8s6z38oUrqMc");

        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();

        Query query = new Query(request.getParameter("q"));

        String tags = request.getParameter("tags");

        String zone = request.getParameter("zone");

        String users = request.getParameter("users");

        Map<String, LatLon> latslongs = new HashMap();

        String[] tagsArray = null;
        if (tags != null) {
            tagsArray = tags.split(",");
        }

        String[] userArray = null;

        if (users != null) {
            userArray = users.split(",");
            int count = userArray.length;
            usuarios = new String[count];
            latitud = new String[count];
            longitud = new String[count];
            for (int i = 0; i < userArray.length; i++) {
                temp = userArray[i];
                if (temp != null) {
                    int hit1 = temp.indexOf("[");
                    int hit2 = temp.indexOf(";");
                    int hit3 = temp.indexOf("]");
                    latslongs.put(temp.substring(0, hit1),
                            new LatLon(temp.substring(hit1 + 1, hit2), temp.substring(hit2 + 1, hit3)));
                    /*
                     * usuarios[i] = temp.substring(0, hit1); latitud[i] =
                     * temp.substring(hit1 + 1, hit2); longitud[i] =
                     * temp.substring(hit2 + 1, hit3);
                     */
                }
            }
        }

        QueryResult result;

        result = twitter.search(query);

        List<Post> postList = new ArrayList();
        List<PostType> postsList = new ArrayList();

        Post solrPost;
        PostType post;
        //List<LinkType> links = new ArrayList();
        List<ActionType> actions;
        ArrayList<User> toUsers = new ArrayList();

        ArrayList<LinkType> links;
        int d;

        InputStream stream = getServletContext().getResourceAsStream("/WEB-INF/servlet.properties");
        Properties props = null;
        if (props == null) {
            props = new Properties();
            props.load(stream);
        }
        ZoneDao zoneDao = new ZoneDao(props.getProperty("db_host"),
                Integer.valueOf(props.getProperty("db_port")), props.getProperty("db_name"));
        PlaceDao placeDao = new PlaceDao(props.getProperty("db_host"),
                Integer.valueOf(props.getProperty("db_port")), props.getProperty("db_name"));
        Place place = null;
        org.zonales.tagsAndZones.objects.Zone zoneObj = zoneDao
                .retrieveByExtendedString(Utils.normalizeZone(zone));

        for (Tweet tweet : (List<Tweet>) result.getTweets()) {
            d = MAX_TITLE_LENGTH;
            actions = new ArrayList();
            try {
                actions.add(new ActionType("retweets", twitter.getRetweets(tweet.getId()).size()));
                actions.add(new ActionType("replies",
                        twitter.getRelatedResults(tweet.getId()).getTweetsWithReply().size()));
            } catch (TwitterException ex) {
                Logger.getLogger(TwitterRetrieval.class.getName()).log(Level.SEVERE,
                        "Error intentando obtener retweets o replies: {0}", new Object[] { ex });
            }

            solrPost = new Post();
            solrPost.setZone(new Zone(String.valueOf(zoneObj.getId()), zoneObj.getName(),
                    zoneObj.getType().getName(), zoneObj.getExtendedString()));
            solrPost.setSource("Twitter");

            solrPost.setId(String.valueOf(tweet.getId()));

            if (request.getParameter(tweet.getFromUser() + "Place") != null) {
                place = placeDao.retrieveByExtendedString(request.getParameter(tweet.getFromUser() + "Place"));
            } else {
                place = null;
            }
            User usersolr = new User(String.valueOf(tweet.getFromUserId()), tweet.getFromUser(),
                    "http://twitter.com/#!/" + tweet.getFromUser(), tweet.getSource(),
                    place != null
                            ? new org.zonales.entities.Place(String.valueOf(place.getId()), place.getName(),
                                    place.getType().getName())
                            : null);

            if (users != null) {
                /*
                 * for (int i = 0; i < usuarios.length; i++) { if
                 * (tweet.getFromUser().equals(usuarios[i])) {
                 * usersolr.setLatitude(Double.parseDouble(latitud[i]));
                 * usersolr.setLongitude(Double.parseDouble(longitud[i])); }
                }
                 */
                //usersolr.setLatitude(Double.parseDouble(latslongs.get(tweet.getFromUser()).latitud));
                //usersolr.setLongitude(Double.parseDouble(latslongs.get(tweet.getFromUser()).longitud));
            }

            solrPost.setFromUser(usersolr);
            if (tweet.getToUser() != null) {
                toUsers.add(new User(String.valueOf(tweet.getToUserId()), tweet.getToUser(), null,
                        tweet.getSource(), null));
                solrPost.setToUsers(toUsers);
            }
            if (tweet.getText().length() > d) {
                while (d > 0 && tweet.getText().charAt(d - 1) != ' ') {
                    d--;
                }
            } else {
                d = tweet.getText().length() - 1;
            }
            solrPost.setTitle(tweet.getText().substring(0, d)
                    + (tweet.getText().length() > MAX_TITLE_LENGTH ? "..." : ""));
            solrPost.setText(tweet.getText());
            //post.setLinks(new LinksType(links));
            solrPost.setActions((ArrayList<ActionType>) actions);
            solrPost.setCreated(tweet.getCreatedAt().getTime());
            solrPost.setModified(tweet.getCreatedAt().getTime());
            solrPost.setRelevance(
                    actions.size() == 2 ? actions.get(0).getCant() * 3 + actions.get(1).getCant() : 0);
            solrPost.setPostLatitude(
                    tweet.getGeoLocation() != null ? tweet.getGeoLocation().getLatitude() : null);
            solrPost.setPostLongitude(
                    tweet.getGeoLocation() != null ? tweet.getGeoLocation().getLongitude() : null);

            links = new ArrayList<LinkType>();
            links.add(new LinkType("avatar", tweet.getProfileImageUrl()));
            if (tweet.getText() != null && getLinks(tweet.getText()) != null) {
                links.addAll(getLinks(tweet.getText()));
            }

            if (solrPost.getLinks() == null) {
                solrPost.setLinks(new ArrayList<LinkType>());
            }
            solrPost.setLinks(links);

            if (tagsArray != null && tagsArray.length > 0) {
                solrPost.setTags(new ArrayList<String>(Arrays.asList(tagsArray)));
            }

            solrPost.setExtendedString(WordUtils.capitalize((solrPost.getFromUser().getPlace() != null
                    ? solrPost.getFromUser().getPlace().getName() + ", "
                    : "") + solrPost.getZone().getExtendedString().replace("_", " ")));
            postList.add(solrPost);

            post = new PostType();
            post.setZone(new Zone(String.valueOf(zoneObj.getId()), zoneObj.getName(),
                    zoneObj.getType().getName(), zoneObj.getExtendedString()));
            post.setSource("Twitter");

            post.setId(String.valueOf(tweet.getId()));
            User user = new User(String.valueOf(tweet.getFromUserId()), tweet.getFromUser(),
                    "http://twitter.com/#!/" + tweet.getFromUser(), tweet.getSource(),
                    place != null
                            ? new org.zonales.entities.Place(String.valueOf(place.getId()), place.getName(),
                                    place.getType().getName())
                            : null);

            if (users != null) {
                /*
                 * for (int i = 0; i < usuarios.length; i++) { if
                 * (tweet.getFromUser().equals(usuarios[i])) {
                 * user.setLatitude(Double.parseDouble(latitud[i]));
                 * user.setLongitude(Double.parseDouble(longitud[i])); }
                }
                 */
                //user.setLatitude(Double.parseDouble(latslongs.get(tweet.getFromUser()).latitud));
                //user.setLongitude(Double.parseDouble(latslongs.get(tweet.getFromUser()).longitud));
            }

            post.setFromUser(user);

            if (tweet.getToUser() != null) {
                toUsers.add(new User(String.valueOf(tweet.getToUserId()), tweet.getToUser(), null,
                        tweet.getSource(), null));
                post.setToUsers(new ToUsersType(toUsers));
            }

            post.setTitle(tweet.getText().substring(0, d)
                    + (tweet.getText().length() > MAX_TITLE_LENGTH ? "..." : ""));
            post.setText(tweet.getText());
            //post.setLinks(new LinksType(links));
            post.setActions(new ActionsType(actions));
            post.setCreated(String.valueOf(tweet.getCreatedAt().getTime()));
            post.setModified(String.valueOf(tweet.getCreatedAt().getTime()));
            post.setRelevance(
                    actions.size() == 2 ? actions.get(0).getCant() * 3 + actions.get(1).getCant() : 0);
            post.setPostLatitude(tweet.getGeoLocation() != null ? tweet.getGeoLocation().getLatitude() : null);
            post.setPostLongitude(
                    tweet.getGeoLocation() != null ? tweet.getGeoLocation().getLongitude() : null);

            links = new ArrayList<LinkType>();
            links.add(new LinkType("avatar", tweet.getProfileImageUrl()));

            post.setLinks(new LinksType(getLinks(tweet.getText())));

            if (tagsArray != null && tagsArray.length > 0) {
                post.setTags(new TagsType(Arrays.asList(tagsArray)));
            }

            postsList.add(post);

        }
        PostsType posts = new PostsType(postsList);
        Gson gson = new Gson();
        if ("xml".equalsIgnoreCase(request.getParameter("format"))) {
            response.setContentType("application/xml");
            out = response.getWriter();
            try {
                for (PostType postIt : posts.getPost()) {
                    postIt.setVerbatim(gson.toJson(postIt));
                }
                Twitter2XML(posts, out);
            } catch (Exception ex) {
                Logger.getLogger(TwitterRetrieval.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            response.setContentType("text/javascript");
            out = response.getWriter();
            out.println("{post: " + gson.toJson(postList) + "}");
        }

    } catch (TwitterException ex) {
        Logger.getLogger(TwitterRetrieval.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Register.java

License:Open Source License

/**
 * Usage: java twitter4j.examples.tweets.UpdateStatus [text]
 *
 * @param args message//from  w w w  .ja  v a2s  .  c  om
 */
public static void main(String[] args) {
    try {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey("wIb1qVNc0CNXQJxduYIXw")
                .setOAuthConsumerSecret("vTES3U9862wYaxFRdMyD1LRatkq2R42mDyOjXLHIdk");

        Twitter twitter = new TwitterFactory(cb.build()).getInstance();
        AccessToken accessToken = null;
        try {
            // get request token.
            // this will throw IllegalStateException if access token is already available
            RequestToken requestToken = twitter.getOAuthRequestToken();

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            while (null == accessToken) {
                System.out.println("Open the following URL and grant access to your account:");
                System.out.println(requestToken.getAuthorizationURL());
                System.out.print("Enter the PIN(if available) and hit enter after you granted access. [PIN]:");
                String pin = br.readLine();
                try {
                    if (pin.length() > 0) {
                        accessToken = twitter.getOAuthAccessToken(requestToken, pin);
                    } else {
                        accessToken = twitter.getOAuthAccessToken(requestToken);
                    }
                } catch (TwitterException te) {
                    if (401 == te.getStatusCode()) {
                        System.out.println("Unable to get the access token.");
                    } else {
                        te.printStackTrace();
                    }
                }
            }
            System.out.println("Access granted to Twitter.");
            System.out.println("Access token: " + accessToken.getToken());
            System.out.println("Access token secret: " + accessToken.getTokenSecret());
        } catch (IllegalStateException ie) {
            // access token is already available, or consumer key/secret is not set.
            if (!twitter.getAuthorization().isEnabled()) {
                System.out.println("OAuth consumer key/secret is not set.");
                System.exit(-1);
            }
        }
        twitter.updateStatus("Minecraft server successfully registered at " + (new Date()).toString());
        System.out.println("Successfully connected to Twitter.");

        // Write the properties file
        PrintWriter pw = new PrintWriter(new FileWriter("../TwitterEvents.properties"));
        pw.println("accessToken=" + accessToken.getToken());
        pw.println("accessTokenSecret=" + accessToken.getTokenSecret());
        pw.close();

        System.out.println("Your TwitterEvents.properties file has been created with your access tokens.");
        System.out.println("Start Minecraft server to load the remaining default values.");
        System.out.println("Then reload TwitterEvents if you make any changes.");
        System.exit(0);
    } catch (TwitterException te) {
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.out
                .println("Try revoking access to the hModEvents application from your Twitter settings page.");
        System.exit(-1);
    } catch (IOException ioe) {
        System.out.println("Failed to read the system input.");
        System.exit(-1);
    }
}

From source file:GetLiveMedia.java

License:Open Source License

public void TweetCollect(String searchString) throws TwitterException {
    tXCoord = 0;//from   w  w w  .  j  a  v a  2 s .c om
    tYCoord = 0;
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("0c1v1wqqNATaVcWpINaHoW3o5")
            .setOAuthConsumerSecret("a6sEAJ1NLY3cXhkMTrMZF62bIfww6qLvlEetDAU9O09Mp04lyh")
            .setOAuthAccessToken("330427831-RJig6B6YycJL3xQVoEjjyRaujwnr1xHEQGtSHOOc")
            .setOAuthAccessTokenSecret("Da71qk4SN6Nu88mLkugDDR6CftVcgOcz3QB8dHNw4hVbD");
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
    query = new Query("#" + searchString);
    result = twitter.search(query);
    for (Status status : result.getTweets()) {
        try {
            System.out.println(status.getGeoLocation());
            System.out.println(status.getCreatedAt());
            tXCoord = status.getGeoLocation().getLatitude();
            tYCoord = status.getGeoLocation().getLongitude();
            twitterString = ("@" + status.getUser().getScreenName() + ": " + status.getText() + " : " + "("
                    + tXCoord + ", " + tYCoord + ")");
            twitterURL = "https://twitter.com/" + status.getUser().getScreenName() + "/status/"
                    + status.getId();
        } catch (Exception e) {
        }
    }
}

From source file:TwitterListenerSnippet.java

License:BEER-WARE LICENSE

public void twitterConfiguration() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey("34sJKGiU71xaVBVeutDA");
    cb.setOAuthConsumerSecret("sMGrXuf2zbhS29cEV9HYHDeNoU45aoGWcw1t2JbJMMk");
    cb.setOAuthAccessToken("1272243708-woC2NKzPErcj9CAsUGURNOmS9OL4ISdFI9hyQmh");
    cb.setOAuthAccessTokenSecret("D846JFR6nH9v13icgBcLfyNCUVWg53R9jhWwjmwuBU");

    c = cb.build();/*from  w ww.  j  ava 2  s  .  c  om*/
    TwitterFactory tf = new TwitterFactory(c);
    twitter = tf.getInstance();

}

From source file:account.GetRateLimitStatus.java

License:Apache License

public static ConstVars getRateLimit(String[] args) {

    ConstVars StaticVars = new ConstVars();

    try {/*from   w  ww.ja  v  a 2 s  . c  om*/

        // init Twitter OAuth
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(args[1]).setOAuthConsumerSecret(args[2])
                .setOAuthAccessToken(args[3]).setOAuthAccessTokenSecret(args[4]);

        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();

        // it returns RateLimits of all end-points
        Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus();

        // get RateLimit of required end-point
        RateLimitStatus status = rateLimitStatus.get(args[0]);
        String Endpoint = args[0];
        int Limit = status.getLimit();

        int Remaining = status.getRemaining();
        int ResetTimeInSeconds = status.getResetTimeInSeconds();
        int SecondsUntilReset = status.getSecondsUntilReset();

        // set and return rate limit info to ConstVars's variables
        StaticVars.Endpoint = Endpoint;
        StaticVars.Limit = Limit;
        StaticVars.Remaining = Remaining;
        StaticVars.ResetTimeInSeconds = ResetTimeInSeconds;
        StaticVars.SecondsUntilReset = SecondsUntilReset;

    } catch (TwitterException te) {
        if (args.length == 6) {
            System.err
                    .println("Failed to get rate limit status of " + args[5] + " because: " + te.getMessage());
        } else {
            System.err.println("Failed to get rate limit status because: " + te.getMessage());
        }
    }
    return StaticVars;
}

From source file:alberapps.java.noticias.tw.tw4j.ProcesarTwitter4j.java

License:Open Source License

/**
 * Inicializar// ww  w  . j  a va2  s  . c  o m
 */
public void setUp() {

    builder = new ConfigurationBuilder();
    // builder.setUseSSL(true);
    builder.setApplicationOnlyAuthEnabled(true);

    try {

        twitter = new TwitterFactory(builder.build()).getInstance();

        twitter.setOAuthConsumer(Constantes.ck, Constantes.cs);

        // Para que cargue
        OAuth2Token token = twitter.getOAuth2Token();

    } catch (TwitterException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}