List of usage examples for twitter4j TwitterException getMessage
@Override
public String getMessage()
From source file:com.revolucion.secretwit.twitter.TwitterClient.java
License:Open Source License
private void init() { logger.info("Starting Twitter client."); TwitterFactory factory = new TwitterFactory(); twitter = factory.getInstance();/*from ww w . ja v a 2 s. c o m*/ twitter.setOAuthConsumer(consumerKey, consumerSecret); logger.info("OAuth consumer initialized."); AccessToken accessToken = loadAccessToken(); if (accessToken != null) { twitter.setOAuthAccessToken(accessToken); logger.info("Loaded access token."); // signedIn = true; try { user = twitter.verifyCredentials(); } catch (TwitterException e) { logger.error(e.getMessage()); } } }
From source file:com.revolucion.secretwit.twitter.TwitterClient.java
License:Open Source License
private String findExceptionCause(TwitterException exception) { if (exception.exceededRateLimitation()) return "Rate limitation exceeded."; if (exception.isCausedByNetworkIssue()) return "Network issue."; if (exception.resourceNotFound()) return "Resource not found."; return exception.getMessage() + " " + exception.getExceptionCode(); }
From source file:com.revolucion.secretwit.ui.SignupPane.java
License:Open Source License
private void init() { labelInfo = new MultilineLabel( "SecreTwit uses OAuth authentication for safe access to your Twitter account."); numberAuthorize = new NumberRenderer(1); labelAuthorize = new JLabel("Please first authorize this application on Twitter.com"); buttonAuthorize = new JButton("Sign in to Twitter in browser"); buttonAuthorize.addActionListener(new ActionListener() { @Override/*from w w w.j a va2 s .c o m*/ public void actionPerformed(ActionEvent e) { String authorizationUrl = TwitterClient.getInstance().getAuthorizationUrl(); logger.info("Authorization url: {}", authorizationUrl); SystemUtils.openWebSite(authorizationUrl); /* int option = JOptionPane.showOptionDialog(SignupPane.this, "Please use following link to authorize this application.", "Authorization", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { "Open in browser", "Copy link" }, "Open in browser"); if (option == 0) { // Open url in default browser SystemUtils.openWebSite(authorizationUrl); } else if (option == 1) { // Copy url to clipboard StringSelection contents = new StringSelection(authorizationUrl); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, contents); } */ fieldPin.setEnabled(true); } }); numberPin = new NumberRenderer(2); labelPin = new JLabel("Then enter the PIN provided to you by Twitter.com"); fieldPin = new JTextField(10); fieldPin.setEnabled(false); fieldPin.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { buttonSignIn.setEnabled(e.getLength() != 0); } @Override public void insertUpdate(DocumentEvent e) { buttonSignIn.setEnabled(e.getLength() != 0); } @Override public void changedUpdate(DocumentEvent e) { buttonSignIn.setEnabled(e.getLength() != 0); } }); buttonSignIn = new JButton("Sign in"); buttonSignIn.setEnabled(false); buttonSignIn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String pin = fieldPin.getText(); if (pin != null && !pin.isEmpty()) { try { User authorizedUser = TwitterClient.getInstance().authorize(pin); if (authorizedUser != null) { HeaderPane.getInstance().setPlace("@home"); HeaderPane.getInstance().setUserStatus(authorizedUser.getScreenName(), true); ViewManager.getInstance().showTimelineView(); TimelinePane.getInstance().reload(); MessagePane.getInstance().setEnabled(true); } } catch (TwitterException te) { logger.error("Authorization error. {} - {}", te.getExceptionCode(), te.getMessage()); JOptionPane.showMessageDialog(SignupPane.this, "<html><b>Authorization failed.</b><br>" + te.getMessage(), "Authorization Error", JOptionPane.ERROR_MESSAGE); } } } }); buttonCancel = new JButton("Cancel"); buttonCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { HeaderPane.getInstance().setPlace("@public"); HeaderPane.getInstance().setUserStatus(null, false); ViewManager.getInstance().showTimelineView(); } }); add(labelInfo, "span, growx, wrap"); add(numberAuthorize, "spany 2"); add(labelAuthorize, "wrap"); add(buttonAuthorize, "growx, wrap"); add(numberPin, "spany 2"); add(labelPin, "wrap"); add(fieldPin, "split 2"); add(buttonSignIn, "growx, wrap"); add(buttonCancel, "span, tag cancel"); }
From source file:com.rhymestore.twitter.util.TwitterUtils.java
License:Open Source License
/** * Checks if the exception cause is a duplicate tweet. * /* ww w. j av a2 s . c o m*/ * @param ex The exception to check. * @return Boolean indicating if the exception cause is a duplicate tweet. */ public static boolean isDuplicateTweetError(final TwitterException ex) { return ex.getStatusCode() == HttpResponseCode.FORBIDDEN && ex.getMessage().contains(DUPLICATE_TWEET_ERROR); }
From source file:com.robertszkutak.androidexamples.twitterexample.AndroidTwitterExample.java
License:Open Source License
public boolean isAuthenticated() { if (token == null || secret == null || token == "" || secret == "") { debug = ""; debugStatus.setText(debug);/*from www . j a v a 2 s. co m*/ return false; } else { AccessToken a = new AccessToken(token, secret); Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); twitter.setOAuthAccessToken(a); try { twitter.getAccountSettings(); return true; } catch (TwitterException e) { debug += "\n\n" + e.getMessage(); debugStatus.setText(debug); return false; } } }
From source file:com.rowland.hashtrace.sync.TweetHashTracerSyncAdapter.java
License:Apache License
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {//from w w w . j a v a 2s.c om Log.d(LOG_TAG, "Starting sync"); // Getting the hashtag to send to the API String hashTagQuery = Utility.getPreferredHashTag(getContext()); long hashTagId = addHashTag(hashTagQuery, hashTagQuery); ArrayList<Tweet> tweetArrayList = new ArrayList<Tweet>(); List<Status> statuses = new ArrayList<Status>(); try { mTwitter = Utility.getTwitter(); statuses = mTwitter.search(new Query(hashTagQuery)).getTweets(); for (Status s : statuses) { Tweet tweet = Utility.createTweet(s); tweetArrayList.add(tweet); } } catch (TwitterException e) { e.printStackTrace(); } try { // Insert the new tweet information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(tweetArrayList.size()); for (int i = 0; i < tweetArrayList.size(); i++) { // These are the values that will be collected. Tweet tweet = tweetArrayList.get(i); long tweet_id = tweet.getTweetId(); String tweet_text = tweet.getTweetText(); Date tweet_text_date = tweet.getTweetTextDate(); int tweet_text_retweet_count = tweet.getTweetRetweetCount(); int tweet_text_favourite_count = tweet.getTweetFavouriteCount(); int tweet_text_mentions_count = tweet.getTweetMentionsCount(); String user_name = tweet.getUserName(); String user_image_url = tweet.getUserImageUrl(); String user_cover_url = tweet.getUserCoverUrl(); String user_location = tweet.getUserLocation(); String user_description = tweet.getUserDescription(); ContentValues tweetValues = new ContentValues(); tweetValues.put(TweetEntry.COLUMN_HASHTAG_KEY, hashTagId); tweetValues.put(TweetEntry.COLUMN_TWEET_TEXT_DATE, TweetHashTracerContract .getDbDateString(tweet_text_date, EDbDateLimit.DATE_FORMAT_NOW_LIMIT)); tweetValues.put(TweetEntry.COLUMN_TWEET_ID, tweet_id); tweetValues.put(TweetEntry.COLUMN_TWEET_TEXT, tweet_text); tweetValues.put(TweetEntry.COLUMN_TWEET_TEXT_RETWEET_COUNT, tweet_text_retweet_count); tweetValues.put(TweetEntry.COLUMN_TWEET_TEXT_FAVOURITE_COUNT, tweet_text_favourite_count); tweetValues.put(TweetEntry.COLUMN_TWEET_TEXT_MENTIONS_COUNT, tweet_text_mentions_count); tweetValues.put(TweetEntry.COLUMN_TWEET_USERNAME, user_name); tweetValues.put(TweetEntry.COLUMN_TWEET_USERNAME_IMAGE_URL, user_image_url); tweetValues.put(TweetEntry.COLUMN_TWEET_USERNAME_COVER_URL, user_cover_url); tweetValues.put(TweetEntry.COLUMN_TWEET_USERNAME_LOCATION, user_location); tweetValues.put(TweetEntry.COLUMN_TWEET_USERNAME_DESCRIPTION, user_description); cVVector.add(tweetValues); } if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); int insertNo = getContext().getContentResolver().bulkInsert(TweetEntry.CONTENT_URI, cvArray); // Get's a calendar object with the current time. Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -3); // Signifies 3 days ago's date String previousDate = TweetHashTracerContract.getDbDateString(cal.getTime(), EDbDateLimit.DATE_FORMAT_NOW_LIMIT); getContext().getContentResolver().delete(TweetEntry.CONTENT_URI, TweetEntry.COLUMN_TWEET_TEXT_DATE + " <= ?", new String[] { previousDate }); notifyWeather(); } Log.d(LOG_TAG, "FetchTweetTask Complete. " + cVVector.size() + " Inserted"); } catch (Exception e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } // This will only happen if there was an error getting or parsing the forecast. return; }
From source file:com.smart.home.SmartHomeAdapter.java
License:Open Source License
@Override public void update(final StructureSnapshot structureSnapshot) { try {/*from w w w. j ava2 s . c o m*/ twitterService.update(structureSnapshot); } catch (TwitterException e) { LOG.error("Got TwitterException for structure event: {}", e.getMessage()); } }
From source file:com.smart.home.SmartHomeAdapter.java
License:Open Source License
@Override public void update(final DeviceSnapshot deviceSnapshot) { try {//w w w. j av a 2s .co m twitterService.update(deviceSnapshot); } catch (TwitterException e) { LOG.error("Got TwitterException for device state event: {}", e.getMessage()); } }
From source file:com.SocialAccess.TwitterSearch.java
public static void searchWhomUserFollow() { List<String[]> data = CSVutil.readCSV(Constants.CSV_FILE_NAME); String[] people = data.get(0); System.out.print(people[0]);/*from www.j a v a2 s . c o m*/ try { Twitter twitter = new TwitterFactory().getInstance(); long cursor = -1; IDs ids; System.out.println("Listing following ids."); do { ids = twitter.getFriendsIDs("derekmizak", cursor); for (long id : ids.getIDs()) { System.out.println(id); } } while ((cursor = ids.getNextCursor()) != 0); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get friends' ids: " + te.getMessage()); System.exit(-1); } }
From source file:com.SocialAccess.TwitterSearch.java
public static void ShowFriendsListNames() { List<String[]> data = CSVutil.readCSV(Constants.CSV_FILE_NAME); String[] people = data.get(0); try {/* w w w. j a v a 2 s . co m*/ Twitter twitter = new TwitterFactory().getInstance(); ResponseList<Friendship> friendships = twitter.lookupFriendships(people); for (Friendship friendship : friendships) { System.out.println("@" + friendship.getScreenName() + " following: " + friendship.isFollowing() + " followed_by: " + friendship.isFollowedBy()); } System.out.println("Successfully looked up friendships [" + people[0] + "]."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to lookup friendships: " + te.getMessage()); System.exit(-1); } }