Example usage for twitter4j TwitterException toString

List of usage examples for twitter4j TwitterException toString

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:TwitterDownload.TwitterHandler.java

public String auth(String callBack) {
    try {/*  ww w . j a  v  a 2  s  . c o m*/
        requestToken = twitter.getOAuthRequestToken(callBack);
        return requestToken.getAuthorizationURL();
    } catch (TwitterException ex) {
        String s = ex.toString();
    } catch (Exception ex) {
        String s = ex.toString();
    }
    return null;
}

From source file:TwitterDownload.TwitterHandler.java

public AccessToken getAccessToken(String verifier) {
    try {//  www  .j  a va  2s .c  o  m
        return twitter.getOAuthAccessToken(requestToken, verifier);
    } catch (TwitterException ex) {
        String s = ex.toString();
    } catch (Exception ex) {
        String s = ex.toString();
    }
    return null;
}

From source file:TwitterDownload.TwitterHandler.java

public List<Status> getUserTimeline(String searchPhrase, int pageSize) throws TwitterException {
    String userName = searchPhrase;

    if (!userName.contains(" ")) {
        if (!userName.startsWith("@"))
            return getSearchTweets(userName, pageSize);

        long lastID = Long.MAX_VALUE;
        ArrayList<Status> tweets = new ArrayList<Status>();
        int count = 200;

        try {// w  ww  .  j  a  va2  s  .c o  m
            int i = 0;
            while (tweets.size() < pageSize) {
                i++;
                if (pageSize - tweets.size() > 200)
                    count = 200;
                else
                    count = pageSize - tweets.size();

                Paging page = new Paging(i, count);
                //page.maxId(lastID);

                List<Status> l = twitter.getUserTimeline(userName, page);

                tweets.addAll(l);

                if (l.size() < 200) {
                    break;
                }

                for (Status t : tweets) {
                    if (t.getId() < lastID)
                        lastID = t.getId();
                    else if (t.getId() == lastID)
                        break;
                }
            }

            return (List<Status>) tweets;
        } catch (TwitterException ex) {
            String s = ex.toString();
            //TODO: needs to be refined to only include user not found exception
            if (ex.resourceNotFound())
                return getSearchTweets(searchPhrase, pageSize);
        } catch (Exception ex) {
            String s = ex.toString();
            return null;
        }
    }
    //else
    return getSearchTweets(userName, pageSize);
}

From source file:TwitterDownload.TwitterHandler.java

public List<Status> getSearchTweets(String searchPhrase, int pageSize) {
    if (pageSize > 18000)
        pageSize = 18000;/*ww w.j  av a 2 s.co m*/

    ArrayList<Status> tweets = new ArrayList<Status>();
    //boolean last = false;

    try {
        Query query = new Query(searchPhrase);

        int limit = getRemainingSearchRateLimit();

        while (tweets.size() < pageSize && query != null && limit > 0) {
            if (pageSize - tweets.size() > 100)
                query.setCount(100);
            else
                query.setCount(pageSize - tweets.size());

            QueryResult result = twitter.search(query);

            tweets.addAll(result.getTweets());

            query = result.nextQuery();

            limit = getRemainingSearchRateLimit();
        }

        return (List<Status>) tweets;
    } catch (TwitterException ex) {
        String s = ex.toString();
        if (ex.exceededRateLimitation())
            return null;
    } catch (IllegalStateException ex) {
        String s = ex.toString();
    }
    return null;
}

From source file:TwitterDownload.TwitterHandler.java

public long getUserID() {
    try {//from   w w  w. ja  va  2s.  c  om
        return twitter.getId();
    } catch (TwitterException ex) {
        String s = ex.toString();
    } catch (IllegalStateException ex) {
        String s = ex.toString();
    }
    return -1;
}

From source file:TwitterDownload.TwitterHandler.java

public String getUserName() {
    try {/*from   ww w.  ja  v a  2 s .com*/
        long userID = twitter.getId();
        return twitter.showUser(userID).getName();
    } catch (TwitterException ex) {
        String s = ex.toString();
    } catch (IllegalStateException ex) {
        String s = ex.toString();
    }
    return null;

}

From source file:TwitterDownload.TwitterHandler.java

public String getScreenName() {
    try {/*from  w  w  w  .ja  va 2  s. c  o  m*/
        return twitter.getScreenName();
    } catch (TwitterException ex) {
        String s = ex.toString();
    } catch (IllegalStateException ex) {
        String s = ex.toString();
    }
    return null;
}

From source file:TwitterDownload.TwitterHandler.java

public int getRemainingRateLimit() {
    try {/*  w  ww. java2s .co  m*/
        RateLimitStatus rateLimit = twitter.getRateLimitStatus("statuses").get("/statuses/user_timeline");
        int restTime = rateLimit.getSecondsUntilReset();
        return rateLimit.getRemaining();
    } catch (TwitterException ex) {
        String s = ex.toString();
    } catch (IllegalStateException ex) {
        String s = ex.toString();
    }
    return -1;
}

From source file:TwitterDownload.TwitterHandler.java

public int getRemainingSearchRateLimit() {
    try {/*www.ja  v a  2  s. c o  m*/
        RateLimitStatus rateLimit = twitter.getRateLimitStatus("search").get("/search/tweets");
        int restTime = rateLimit.getSecondsUntilReset();
        return rateLimit.getRemaining();
    } catch (TwitterException ex) {
        String s = ex.toString();
    } catch (IllegalStateException ex) {
        String s = ex.toString();
    }
    return -1;
}