Example usage for twitter4j TwitterException getErrorMessage

List of usage examples for twitter4j TwitterException getErrorMessage

Introduction

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

Prototype

public String getErrorMessage() 

Source Link

Document

Returns error message from the API if available.

Usage

From source file:org.wandora.application.tools.extractors.twitter.TwitterJSONExtractor.java

License:Open Source License

private void handleStatus(JSONObject json, Topic baseTopic, TopicMap tm) {
    Status s;//from   www.j a v  a 2  s .c o  m
    try {
        s = TwitterObjectFactory.createStatus(json.toString());
    } catch (TwitterException te) {
        log("Couldn't parse status JSON. The error was:\n");
        log(te.getErrorMessage());
        return;
    }

    Topic t = reifyTweet(s, tm);
    try {
        t.addType(baseTopic);
    } catch (TopicMapException tme) {
        log("Couldn't associate status with base topic. The error was:\n");
        log(tme.getMessage());
    }

}

From source file:org.zoneproject.extractor.twitterreader.TwitterApi.java

License:Open Source License

public static ArrayList<Item> getFluxFromUser(String user, String sourceUri) {
    ArrayList<Item> result = new ArrayList<Item>();
    try {//from  w  w w. j  a  va2  s  . c om

        Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(Config.getVar("Twitter-OAuth-customer"),
                Config.getVar("Twitter-OAuth-customerKey"));
        twitter.setOAuthAccessToken(new AccessToken(Config.getVar("Twitter-OAuth-access"),
                Config.getVar("Twitter-OAuth-accessKey")));

        List<Status> statusess = twitter.getUserTimeline(user);
        for (Status r : statusess) {
            result.add(TwitterApi.getItemFromStatus(r, sourceUri));
        }

        return result;
    } catch (TwitterException ex) {
        logger.warn(ex.getErrorMessage());
        return result;
    }
}

From source file:t.twitter.TTwitterModule.java

License:Open Source License

@Kroll.method
public void connect(HashMap args) {
    KrollDict arg = new KrollDict(args);

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(arg.optString("apikey", ""))
            .setOAuthConsumerSecret(arg.optString("apisecret", ""))
            .setOAuthAccessToken(arg.optString("accesstoken", ""))
            .setOAuthAccessTokenSecret(arg.optString("accesssecret", ""));
    AsyncTwitterFactory tf = new AsyncTwitterFactory(cb.build());
    twitter = tf.getInstance();/*from  ww  w . ja v a  2 s  .  c  o  m*/

    twitter.addListener(new TwitterAdapter() {
        @Override
        public void updatedStatus(Status status) {
            Log.d("Twitter", "text: " + status.getText());
        }

        @Override
        public void searched(QueryResult result) {
            HashMap<String, KrollDict[]> event = new HashMap<String, KrollDict[]>();
            List<Status> tweets = result.getTweets();
            KrollDict[] dList = new KrollDict[tweets.size()];

            // sort tweets
            Collections.sort(tweets, new Comparator<Status>() {
                public int compare(Status o1, Status o2) {

                    if (desc) {
                        if (o2.getId() < o1.getId()) {
                            return 1;
                        } else {
                            return -1;
                        }
                    } else {
                        if (o2.getId() > o1.getId()) {
                            return 1;
                        } else {
                            return -1;
                        }
                    }
                }
            });

            // return tweets to titanium
            int i = 0;
            for (Status tweet : tweets) {
                if (lastID == -1 || lastID < tweet.getId()) {
                    KrollDict d = new KrollDict();
                    d.put("username", tweet.getUser().getScreenName());
                    d.put("userimage", tweet.getUser().getProfileImageURL());
                    d.put("text", tweet.getText());
                    d.put("date", tweet.getCreatedAt());
                    d.put("id", Long.toString(tweet.getId()));
                    dList[i] = d;
                    lastID = tweet.getId();
                    i++;
                }
            }

            KrollDict[] dList2 = new KrollDict[i];

            // shorten array
            System.arraycopy(dList, 0, dList2, 0, i);

            event.put("tweets", dList2);
            success.call(getKrollObject(), event);

            synchronized (LOCK) {
                LOCK.notify();
            }
        }

        @Override
        public void verifiedCredentials(User user) {

            HashMap<String, KrollDict> event = new HashMap<String, KrollDict>();
            KrollDict d = new KrollDict();

            d.put("user_name", user.getName());
            d.put("screen_name", user.getScreenName());
            d.put("image_path", user.getProfileImageURL());
            event.put("user_info", d);
            success.call(getKrollObject(), event);
            synchronized (LOCK) {
                LOCK.notify();
            }
        }

        @Override
        public void onException(TwitterException e, TwitterMethod method) {
            synchronized (LOCK) {
                LOCK.notify();
            }
            Log.e("twitter", "error: " + e.getErrorMessage());
        }
    });
    Log.d("Twitter", "connected");
}