Example usage for twitter4j TwitterException getMessage

List of usage examples for twitter4j TwitterException getMessage

Introduction

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

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:tkwatch.WatchlistPanel.java

License:Open Source License

/**
 * Constructor with title argument./*from w  w  w  . ja v  a2 s.c o  m*/
 * 
 * @param string
 *            The title of the watchlist panel.
 */
public WatchlistPanel(String string) {
    tabReference = this;
    try {
        Database.connectToDatabase();
    } catch (ClassNotFoundException e) {
        TradekingException.handleException(e);
    } catch (SQLException e) {
        TradekingException.handleException(e);
    }
    final ArrayList<WatchlistItem> items = getItemsArrayList();
    final Iterator<WatchlistItem> itemIterator = items.iterator();
    while (itemIterator.hasNext()) {
        instrumentListModel.addElement(itemIterator.next().getInstrument());
    }
    instrumentList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (instrumentList.getSelectedValue() != null) {
                final String symbol = instrumentList.getSelectedValue().toString();
                final WatchlistItem item = WatchlistItem.retrieve(symbol);
                getCostBasisField().setText(Double.toString(item.getCostBasis()));
                getQuantityField().setText(Double.toString(item.getQuantity()));
                getNotationField().setText(Utilities.unPrep(item.getNotation()));
            }
        }

    });
    instrumentList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    instrumentList.setLayoutOrientation(JList.VERTICAL);
    instrumentList.setFont(Constants.DEFAULT_FONT);
    instrumentList.setFixedCellWidth(Constants.FIELD_WIDTH_NARROW);
    if (instrumentList.getComponentCount() >= 0)
        instrumentList.setSelectedIndex(0);

    JPanel costQuantityPanel = new JPanel(new GridBagLayout());
    costQuantityPanel.add(costBasisLabel, Utilities.getConstraints(0, 0, 1, 1, GridBagConstraints.SOUTH));
    costQuantityPanel.add(quantityLabel, Utilities.getConstraints(1, 0, 1, 1, GridBagConstraints.SOUTH));
    costQuantityPanel.add(getCostBasisField(), Utilities.getConstraints(0, 1, 1, 1, GridBagConstraints.CENTER));
    costQuantityPanel.add(getQuantityField(), Utilities.getConstraints(1, 1, 1, 1, GridBagConstraints.CENTER));
    costQuantityPanel.add(notationLabel, Utilities.getConstraints(0, 2, 2, 1, GridBagConstraints.SOUTH));

    JPanel buttonPanel = new JPanel(new GridBagLayout());
    buttonAdd.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            // TODO Currently opens a new window; use a panel in the main frame instead.
            final ItemAddPanel addWindow = new ItemAddPanel(tabReference);
            final JFrame frame = new JFrame();
            frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(addWindow);
            frame.pack();
            frame.setSize(Constants.INITIAL_FRAME_WIDTH, Constants.INITIAL_FRAME_HEIGHT);
            Utilities.centerWindow(frame);
            frame.setVisible(true);
        }
    });
    buttonPanel.add(buttonAdd, Utilities.getConstraints(0, 0, 1, 1, GridBagConstraints.CENTER));
    buttonUpdate.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            final String instrumentSelected = (String) instrumentList.getSelectedValue();
            final int response = JOptionPane.showConfirmDialog(null,
                    "Really update " + instrumentSelected + " in the database?");
            if (response != JOptionPane.YES_OPTION)
                return;
            final WatchlistItem itemToUpdate = WatchlistItem.retrieve(instrumentSelected);
            itemToUpdate.setCostBasis(Double.parseDouble(getCostBasisField().getText()));
            itemToUpdate.setNotation(Utilities.prep(getNotationField().getText()));
            itemToUpdate.setQuantity(Double.parseDouble(getQuantityField().getText()));
            if (!WatchlistItem.update(itemToUpdate)) {
                Utilities.errorMessage("Couldn't update " + instrumentSelected);
                return;
            }
            synchWatchlistWithTk();
        }
    });
    buttonPanel.add(buttonUpdate, Utilities.getConstraints(1, 0, 1, 1, GridBagConstraints.CENTER));
    buttonDelete.addActionListener(new ActionListener() {
        // TODO deleting all instruments leaves last instrument's data in
        // cost basis, quantity and notation windows.
        public void actionPerformed(final ActionEvent e) {
            final String symbolToDelete = (String) instrumentList.getSelectedValue();
            final int response = JOptionPane.showConfirmDialog(null,
                    "Really delete " + symbolToDelete + " from the watchlist?");
            if (response != JOptionPane.YES_OPTION)
                return;
            if (!WatchlistItem.delete(symbolToDelete)) {
                Utilities.errorMessage("Couldn't delete item " + symbolToDelete);
                return;
            }
            instrumentListModel.removeElementAt(instrumentList.getSelectedIndex());
            if (tweet.isSelected()) {
                final Twitter twitter = new TwitterFactory().getInstance();
                final String update;
                try {
                    update = "Stopped watching " + symbolToDelete + " on @TradeKing.";
                    twitter.updateStatus(update);
                } catch (TwitterException e1) {
                    Utilities.errorMessage(e1.getMessage());
                }
            }
            if (instrumentList.getComponentCount() >= 0)
                instrumentList.setSelectedIndex(0);
            synchWatchlistWithTk();
        }
    });
    buttonPanel.add(buttonDelete, Utilities.getConstraints(2, 0, 1, 1, GridBagConstraints.CENTER));

    final JPanel tweetPanel = new JPanel(new FlowLayout());
    final ImageIcon iconColor = new ImageIcon("twitterColor.gif");
    final ImageIcon iconGray = new ImageIcon("twitterGray.gif");
    getTweetLabel().setIcon(iconColor);
    tweet.setSelected(true);
    tweet.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent arg0) {
            if (tweet.isSelected()) {
                getTweetLabel().setIcon(iconColor);
                // to tweet or not to tweet is decided by tweet.isSelected()
            } else {
                getTweetLabel().setIcon(iconGray);
            }
        }
    });
    tweetPanel.add(tweet);
    tweetPanel.add(getTweetLabel());

    final JPanel bottomPanel = new JPanel(new BorderLayout());
    bottomPanel.add(buttonPanel, BorderLayout.NORTH);
    bottomPanel.add(tweetPanel, BorderLayout.SOUTH);

    final JPanel managementPanel = new JPanel(new BorderLayout());
    managementPanel.add(costQuantityPanel, BorderLayout.NORTH);
    managementPanel.add(notationFieldScrollPane, BorderLayout.CENTER);
    managementPanel.add(bottomPanel, BorderLayout.SOUTH);

    final JPanel symbolPanel = new JPanel(new BorderLayout());
    symbolPanel.add(instrumentListLabel, BorderLayout.NORTH);
    symbolPanel.add(instrumentListScrollPane, BorderLayout.CENTER);

    this.setLayout(new BorderLayout(Constants.GAP, Constants.GAP));
    this.add(symbolPanel, BorderLayout.WEST);
    this.add(managementPanel, BorderLayout.CENTER);
}

From source file:tokyo.ryogo.dropkick.sns.twitter.TwitterWrapper.java

License:Apache License

public boolean updateStatus() {

    // Twitter???????????
    if (mTwitter == null) {
        mTwitter = DKTwitter.getTwitterInstance(mContext);
    }//www  .  j a  v a  2  s .  c o  m

    try {
        // 
        mTwitter.updateStatus(mTweetText);
        return true;
    } catch (TwitterException e) {
        // ?
        mLastErrorMessage = mContext.getString(R.string.msg_err_internal) + e.getMessage();
        return false;
    }

}

From source file:traffickarmasent.newgetpage.java

public static void main(String[] args) throws IOException {
    // gets Twitter instance with default credentials
    Twitter twitter = new TwitterFactory().getInstance();
    try {//from  ww  w  .j a  v  a2s  .  co m
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true);
        cb.setOAuthConsumerKey("GPtsu5cjC08KTOEojEoaHw");
        cb.setOAuthConsumerSecret("SsgeXn73bN4CXUYtJfEdKOwBxVTmAEPvmFo3q2CX45w");
        cb.setOAuthAccessToken("154196958-J1Gqy86jmQ6YSoFVVq69bmbJB0acGxiDEocxtvre");
        cb.setOAuthAccessTokenSecret("DpTJr3huuDy2qMwsCMgsTn5yNbi0oQzSDGhDDWQsLog");
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter1 = tf.getInstance();
        List<Status> statuses;
        String user;
        String[] users = { "livetrafficsyd", "trafficnsw", "sydtraffic_cs", "WazeTrafficSYD",
                "livetrafficnsw" };
        Date[] d_users = { new Date(99, 2, 12), new Date(99, 2, 12), new Date(99, 2, 12), new Date(99, 2, 12),
                new Date(99, 2, 12) };

        while (true) {
            for (int i = 0; i < users.length; i++) {

                statuses = twitter1.getUserTimeline(users[i]);

                for (int j = statuses.size() - 1; j >= 0; j--) {
                    Status st = statuses.get(j);
                    if (d_users[i].before(st.getCreatedAt())) {
                        String message = removeUrl(st.getText());

                        File file = new File("out_sydney_new.txt");

                        //if file doesnt exists, then create it
                        if (!file.exists()) {
                            file.createNewFile();
                        }

                        //true = append file
                        FileWriter fileWritter = new FileWriter(file.getName(), true);
                        BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
                        bufferWritter.write(message + "\n");
                        bufferWritter.close();

                        System.out.println("Done");

                        System.out.println("@" + st.getUser().getScreenName() + " - " + st.getText());
                        d_users[i] = st.getCreatedAt();
                    }
                }
            }
            try {
                Thread.sleep(300000); //1000 milliseconds is one second.
            } catch (InterruptedException ex) {
                Thread.currentThread().interrupt();
            }
            System.out.println("firse");

        }

    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:tweet.Miner.java

License:Apache License

/**
 * Usage: java twitter4j.examples.search.SearchTweets [query]
 *
 * @param toSearch  /*from ww w .ja v a 2  s  .  c  o  m*/
 */
public List<Status> mine(String toSearch) {
    List<Status> results = new ArrayList<Status>();
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET)
            .setOAuthAccessToken(OAUTH_ACCESS_TOKEN).setOAuthAccessTokenSecret(OAUTH_ACCESS_TOKEN_SECRET);
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();

    try {
        Query query = new Query(toSearch);
        query.setCount(100);
        QueryResult result;
        do {
            result = twitter.search(query);
            List<Status> tweets = result.getTweets();
            results.addAll(result.getTweets());
            for (Status tweet : tweets) {
                System.out.println(
                        tweet.getId() + " @ " + tweet.getUser().getScreenName() + " - " + tweet.getText());
            }
        } while ((query = result.nextQuery()) != null);

    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to search tweets: " + te.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }

    return results;
}

From source file:tweetcrawling.Main.java

public static void getRateLimitStatuses(TwitterConfiguration tc_) {
    try {//  w ww.  j a  va  2 s  .  c o m
        //          Twitter twitter = new TwitterFactory().getInstance();
        Map<String, RateLimitStatus> rateLimitStatus = tc_.getTwitter().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());
        }
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get rate limit status: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:tweetcrawling.TweetCrawler.java

public void getTweets(TwitterConfiguration tc_) throws IOException, InterruptedException {

    try {//w  ww  . ja  v a  2 s  .  c  o m

        for (String query_ : Queries) {

            // Ngambil tweet dari tiap page lalu disimpan di Statuses
            int maxTweetCrawled = 3240; // This is the number of the latest tweets that we can crawl, specified by Twitter

            Query query = new Query(query_);
            query.setLang("id");
            QueryResult result;
            do {
                rateLimitHandler(tc_, "/search/tweets"); // Check rate limit first
                //System.out.println("kanya sini");
                result = tc_.getTwitter().search(query);
                List<Status> tweets = result.getTweets();
                for (Status tweet : tweets) {
                    ArrayList<String> ValToWrite = getValueToWrite(tweet);
                    writeValue(ValToWrite, OutputFile);
                    System.out.println(
                            "@" + tweet.getUser().getScreenName() + " - " + tweet.getText().replace("\n", " "));
                }
                addStatuses(tweets);

            } while ((query = result.nextQuery()) != null);

            //printTweets(OutputFile); // Printing out crawling result per page of this keywords
            //emptyStatuses(); // Empty out the current attribute Statuses so that it can be used for other keywords    

        }

    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get timeline: " + te.getMessage());
        if (te.exceededRateLimitation()) {
            System.out.println("Rate limit status: " + te.getRateLimitStatus());
        }
        System.exit(-1);
    }

}

From source file:tweete.Tweete.java

License:Open Source License

public void updateTweete(String sta) {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("######################")
            .setOAuthConsumerSecret("######################")
            .setOAuthAccessToken("############################################")
            .setOAuthAccessTokenSecret("############################################");
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();/*from   ww w  .ja  va2s.  c  o  m*/

    try {

        twitter.updateStatus(sta);

        System.out.println("Successfully updated the status in Twitter.");

    } catch (TwitterException te) {

        if (401 == te.getStatusCode()) {
            System.out.println("Unable to get the access token.");
        }

        else if (92 == te.getStatusCode()) {
            System.out.println("SSL is required");
        }

        else {
            System.out.println("Failed to get timeline: " + te.getMessage());
            System.exit(-1);
        }
    } catch (Exception e) {
        System.out.println("Something went wrong");
    }
}

From source file:tweete.Tweete.java

License:Open Source License

public void showTimeline() {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("######################")
            .setOAuthConsumerSecret("######################")
            .setOAuthAccessToken("############################################")
            .setOAuthAccessTokenSecret("############################################");
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();/*from  ww  w . ja  v  a2s  .  co  m*/

    try {
        ResponseList<Status> a = twitter.getUserTimeline(new Paging(1, 10));
        String statuses = "";
        for (Status b : a) {
            statuses = statuses + b.getText() + "\n\n---------------------------------------\n\n";

        }

        new TweeteTimeline().Timeline(statuses);
    } catch (TwitterException te) {
        //te.printStackTrace();

        if (401 == te.getStatusCode()) {
            System.out.println("Unable to get the access token.");
        }

        else if (92 == te.getStatusCode()) {
            System.out.println("SSL is required");
        }

        else {
            System.out.println("Failed to get timeline: " + te.getMessage());
            System.exit(-1);
        }
    } catch (Exception e) {
        System.out.println("Something went wrong");
    }
}

From source file:tweete.Tweete.java

License:Open Source License

public void sendMessage(String id, String msg) {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("######################")
            .setOAuthConsumerSecret("######################")
            .setOAuthAccessToken("############################################")
            .setOAuthAccessTokenSecret("############################################");
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();// w w  w  .  j  a  v  a  2s. com

    try {
        DirectMessage message = null;
        message = twitter.sendDirectMessage(id, msg);
        System.out.println("Sent: " + message.getText() + " to @" + message.getRecipientScreenName());

    } catch (TwitterException te) {
        //te.printStackTrace();

        if (401 == te.getStatusCode()) {
            System.out.println("Unable to get the access token.");
        }

        else if (92 == te.getStatusCode()) {
            System.out.println("SSL is required");
        }

        else {
            System.out.println("Failed to get timeline: " + te.getMessage());
            System.exit(-1);
        }
    } catch (Exception e) {
        System.out.println("Something went wrong");
    }

}

From source file:tweets_stock_price_prediction.TweetsManager.java

public ArrayList<String> getTweets(String topic, String fromDate, String toDate) {

    //Twitter twitter = new TwitterFactory().getInstance();
    System.out.println("*** TWITTER QUERY: " + topic);
    ArrayList<String> tweetList = new ArrayList<String>();
    try {/*from  w  w w.  jav  a2 s.co m*/
        Query query = new Query(topic);
        query.setLang("en");
        //query.setCount(count);
        query.setSince(fromDate);
        query.setUntil(toDate);
        QueryResult result;
        do {
            result = twitter.search(query);
            List<Status> tweets = result.getTweets();
            for (Status tweet : tweets) {
                //System.out.print("LANGUAGE " + tweet.getLang() + "\n\n");
                //if (tweet.getLang().equals("en")) {
                tweetList.add(tweet.getText());
                //}
            }
        } while ((query = result.nextQuery()) != null);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to search tweets: " + te.getMessage());
    }

    System.out.println("************ TWEET LIST: " + tweetList.size());
    return tweetList;
}