List of usage examples for twitter4j TwitterException getMessage
@Override
public String getMessage()
From source file:com.carolinarollergirls.scoreboard.xml.TwitterXmlDocumentManager.java
License:GNU General Public License
protected void processChildElement(Element e) { String text = editor.getText(e); boolean nullText = (null == text); try {/* w w w . jav a2 s . co m*/ if (e.getName().equals("Start") && !nullText && !"".equals(text)) startOAuth(e); else if (e.getName().equals("Stop") && editor.isTrue(e)) logout(); else if (e.getName().equals("SetOAuthVerifier") && !nullText) setOAuthVerifier(e); else if (e.getName().equals("Tweet") && !nullText) tweet(e); else if (e.getName().equals("ConditionalTweet") && editor.hasPI(e, "Remove")) removeConditionalTweet(e); else if (e.getName().equals("ConditionalTweet")) updateConditionalTweet(e); else if (e.getName().equals("AuthURL") && !nullText && "".equals(text)) clearAuthURL(); else if (e.getName().equals("Denied") && editor.isTrue(e)) denied(); else if (e.getName().equals("TestMode")) setTestMode(editor.isTrue(e)); } catch (NoTwitterViewerException ntvE) { setError("Twitter Viewer not loaded"); } catch (TwitterException tE) { setError("Twitter Exception : " + tE.getMessage()); } catch (IllegalArgumentException iaE) { setError(iaE.getMessage()); } }
From source file:com.daiv.android.twitter.services.MentionsRefreshService.java
License:Apache License
@Override public void onHandleIntent(Intent intent) { sharedPrefs = getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); Context context = getApplicationContext(); AppSettings settings = AppSettings.getInstance(context); // if they have mobile data on and don't want to sync over mobile data if (Utils.getConnectionStatus(context) && !settings.syncMobile) { return;//from ww w. j a v a 2s . c o m } try { Twitter twitter = Utils.getTwitter(context, settings); int currentAccount = sharedPrefs.getInt("current_account", 1); MentionsDataSource dataSource = MentionsDataSource.getInstance(context); long[] lastId = dataSource.getLastIds(currentAccount); Paging paging; paging = new Paging(1, 200); if (lastId[0] > 0) { paging.sinceId(lastId[0]); } List<twitter4j.Status> statuses = twitter.getMentionsTimeline(paging); int inserted = MentionsDataSource.getInstance(context).insertTweets(statuses, currentAccount); sharedPrefs.edit().putBoolean("refresh_me", true).commit(); sharedPrefs.edit().putBoolean("refresh_me_mentions", true).commit(); if (settings.notifications && settings.mentionsNot && inserted > 0) { if (intent.getBooleanExtra("from_launcher", false)) { NotificationUtils.refreshNotification(context, true); } else { NotificationUtils.refreshNotification(context); } } if (settings.syncSecondMentions) { startService(new Intent(context, SecondMentionsRefreshService.class)); } } catch (TwitterException e) { // Error in updating status Log.d("Twitter Update Error", e.getMessage()); } }
From source file:com.daiv.android.twitter.services.SecondMentionsRefreshService.java
License:Apache License
@Override public void onHandleIntent(Intent intent) { sharedPrefs = getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); Context context = getApplicationContext(); AppSettings settings = AppSettings.getInstance(context); // if they have mobile data on and don't want to sync over mobile data if (Utils.getConnectionStatus(context) && !settings.syncMobile) { return;/* w w w . j a va 2s . com*/ } boolean update = false; int numberNew = 0; try { Twitter twitter = Utils.getSecondTwitter(context); int currentAccount = sharedPrefs.getInt("current_account", 1); if (currentAccount == 1) { currentAccount = 2; } else { currentAccount = 1; } MentionsDataSource dataSource = MentionsDataSource.getInstance(context); long lastId = dataSource.getLastIds(currentAccount)[0]; Paging paging; paging = new Paging(1, 200); if (lastId > 0) { paging.sinceId(lastId); } List<Status> statuses = twitter.getMentionsTimeline(paging); numberNew = MentionsDataSource.getInstance(context).insertTweets(statuses, currentAccount); if (numberNew > 0) { sharedPrefs.edit().putBoolean("refresh_me_mentions", true).commit(); if (settings.notifications && settings.mentionsNot) { NotificationUtils.notifySecondMentions(context, currentAccount); } sendBroadcast(new Intent("com.daiv.android.twitter.REFRESH_SECOND_MENTIONS")); } } catch (TwitterException e) { // Error in updating status Log.d("Twitter Update Error", e.getMessage()); } }
From source file:com.discord.discordbot.eventhandlers.TweetMe.java
private void onTrump(MessageReceivedEvent event) { Paging paging = new Paging(1, 10); try {/* ww w .j a v a 2 s .c om*/ statuses = (ArrayList<Status>) unauthenticatedTwitter.getUserTimeline("google", paging); log.info("ArrayList created size: " + statuses.size()); printMessage(event, statuses.toString()); } catch (TwitterException e) { log.warn("Error could not intitate twitter onTrump"); System.err.println(e.getMessage() + "\n" + e.getStackTrace()); } }
From source file:com.djbrick.twitter_photo_uploader.MSTwitter.java
License:Apache License
/** * Parse result code and message to get twitter error number * @return int with MST_RESULT code./*w ww.j a v a 2s .co m*/ */ protected static int getTwitterErrorNum(TwitterException e, Context context) { int errNum = e.getErrorCode(); String errMsg = e.getMessage(); if (errNum != -1) { // get error code from message sent back from twitter String errNumS = e.getMessage().substring(0, 3); Log.d(MSTwitter.TAG, "errNumS=" + errNumS); try { errNum = Integer.parseInt(errNumS); } catch (NumberFormatException nfe) { errNum = -1; } } int outInt = -1; switch (errNum) { case 401: case 403: case 420: case 503: outInt = errNum; break; default: // first see if it is from bad creditentials if (errMsg.equals("Received authentication challenge is null")) { outInt = MST_RESULT_INVALID_CREDENTIALS; } else { // Create shared preference object to remember this error message. SharedPreferences refs = context.getSharedPreferences(MSTwitter.PERF_FILENAME, Context.MODE_PRIVATE); Editor editor = refs.edit(); editor.putString(MSTwitter.PREF_LAST_TWITTER_ERROR, errMsg + "[code:" + e.getErrorCode() + "]"); editor.commit(); outInt = MST_RESULT_UNKNOWN_ERROR; } } Log.e(MSTwitter.TAG, "Tweeter Error: " + e.getMessage()); return outInt; }
From source file:com.esz.thaifloodreporter.UpdateStatus.java
License:Apache License
/** * Usage: java twitter4j.examples.tweets.UpdateStatus [text] * * @param args message/*from www.ja v a2 s. c o m*/ */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.tweets.UpdateStatus [text]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); try { // get request token. // this will throw IllegalStateException if access token is already available RequestToken requestToken = twitter.getOAuthRequestToken(); System.out.println("Got request token."); System.out.println("Request token: " + requestToken.getToken()); System.out.println("Request token secret: " + requestToken.getTokenSecret()); AccessToken accessToken = null; 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("Got access token."); 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); } } Status status = twitter.updateStatus(args[0]); System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } catch (IOException ioe) { ioe.printStackTrace(); System.out.println("Failed to read the system input."); System.exit(-1); } }
From source file:com.eventattend.portal.bl.TwitterBL.java
License:Open Source License
public TwitterDTO inviteFriend(TwitterDTO twitterDTO) { boolean result = false; String friendScreenName = null; AccessToken accessToken = null;//from w ww. j av a 2s.com friendScreenName = twitterDTO.getUserScreeName(); if (twitterDTO != null) { accessToken = (AccessToken) twitterDTO.getAccessToken(); if (accessToken != null) { twitter.setOAuthAccessToken(accessToken); if (friendScreenName != null) { try { User user = twitter.createFriendship(String.valueOf(friendScreenName)); twitterDTO.setFriendInvited(true); result = true; } catch (TwitterException e) { twitterDTO.setFriendInvited(false); result = false; twitterDTO.setResultMessage(e.getMessage()); e.printStackTrace(); } } twitterDTO.setFriendInvited(result); } } return twitterDTO; }
From source file:com.google.appinventor.components.runtime.Twitter.java
License:Open Source License
/** * Authenticate to Twitter using OAuth/*from w ww.j a va2s.c o m*/ */ @SimpleFunction(description = "Redirects user to login to Twitter via the Web browser using " + "the OAuth protocol if we don't already have authorization.") public void Authorize() { if (consumerKey.length() == 0 || consumerSecret.length() == 0) { form.dispatchErrorOccurredEvent(this, "Authorize", ErrorMessages.ERROR_TWITTER_BLANK_CONSUMER_KEY_OR_SECRET); return; } if (twitter == null) { twitter = new TwitterFactory().getInstance(); } final String myConsumerKey = consumerKey; final String myConsumerSecret = consumerSecret; AsynchUtil.runAsynchronously(new Runnable() { public void run() { if (checkAccessToken(myConsumerKey, myConsumerSecret)) { handler.post(new Runnable() { @Override public void run() { IsAuthorized(); } }); return; } try { // potentially time-consuming calls RequestToken newRequestToken; twitter.setOAuthConsumer(myConsumerKey, myConsumerSecret); newRequestToken = twitter.getOAuthRequestToken(CALLBACK_URL); String authURL = newRequestToken.getAuthorizationURL(); requestToken = newRequestToken; // request token will be // needed to get access token Intent browserIntent = new Intent(Intent.ACTION_MAIN, Uri.parse(authURL)); browserIntent.setClassName(container.$context(), WEBVIEW_ACTIVITY_CLASS); container.$context().startActivityForResult(browserIntent, requestCode); } catch (TwitterException e) { Log.i("Twitter", "Got exception: " + e.getMessage()); e.printStackTrace(); form.dispatchErrorOccurredEvent(Twitter.this, "Authorize", ErrorMessages.ERROR_TWITTER_EXCEPTION, e.getMessage()); DeAuthorize(); // clean up } catch (IllegalStateException ise) { //This should never happen cause it should return // at the if (checkAccessToken...). We mark as an error but let continue Log.e("Twitter", "OAuthConsumer was already set: launch IsAuthorized()"); handler.post(new Runnable() { @Override public void run() { IsAuthorized(); } }); } } }); }
From source file:com.google.appinventor.components.runtime.Twitter.java
License:Open Source License
@Override public void resultReturned(int requestCode, int resultCode, Intent data) { Log.i("Twitter", "Got result " + resultCode); if (data != null) { Uri uri = data.getData();//from w ww .j ava 2 s .c o m if (uri != null) { Log.i("Twitter", "Intent URI: " + uri.toString()); final String oauthVerifier = uri.getQueryParameter("oauth_verifier"); if (twitter == null) { Log.e("Twitter", "twitter field is unexpectedly null"); form.dispatchErrorOccurredEvent(this, "Authorize", ErrorMessages.ERROR_TWITTER_UNABLE_TO_GET_ACCESS_TOKEN, "internal error: can't access Twitter library"); new RuntimeException().printStackTrace(); } if (requestToken != null && oauthVerifier != null && oauthVerifier.length() != 0) { AsynchUtil.runAsynchronously(new Runnable() { public void run() { try { AccessToken resultAccessToken; resultAccessToken = twitter.getOAuthAccessToken(requestToken, oauthVerifier); accessToken = resultAccessToken; userName = accessToken.getScreenName(); saveAccessToken(resultAccessToken); handler.post(new Runnable() { @Override public void run() { IsAuthorized(); } }); } catch (TwitterException e) { Log.e("Twitter", "Got exception: " + e.getMessage()); e.printStackTrace(); form.dispatchErrorOccurredEvent(Twitter.this, "Authorize", ErrorMessages.ERROR_TWITTER_UNABLE_TO_GET_ACCESS_TOKEN, e.getMessage()); deAuthorize(); // clean up } } }); } else { form.dispatchErrorOccurredEvent(this, "Authorize", ErrorMessages.ERROR_TWITTER_AUTHORIZATION_FAILED); deAuthorize(); // clean up } } else { Log.e("Twitter", "uri returned from WebView activity was unexpectedly null"); deAuthorize(); // clean up so we can call Authorize again } } else { Log.e("Twitter", "intent returned from WebView activity was unexpectedly null"); deAuthorize(); // clean up so we can call Authorize again } }
From source file:com.google.appinventor.components.runtime.Twitter.java
License:Open Source License
/** * Sends a Tweet of the currently logged in user. *///from www.j av a2 s. c o m @SimpleFunction(description = "This sends a tweet as the logged-in user with the " + "specified Text, which will be trimmed if it exceeds " + MAX_CHARACTERS + " characters. " + "<p><u>Requirements</u>: This should only be called after the " + "<code>IsAuthorized</code> event has been raised, indicating that the " + "user has successfully logged in to Twitter.</p>") public void Tweet(final String status) { if (twitter == null || userName.length() == 0) { form.dispatchErrorOccurredEvent(this, "Tweet", ErrorMessages.ERROR_TWITTER_SET_STATUS_FAILED, "Need to login?"); return; } // TODO(sharon): note that if the user calls DeAuthorize immediately // after // Tweet it is possible that the DeAuthorize call can slip in // and invalidate the authorization credentials for myTwitter, causing // the call below to fail. If we want to prevent this we could consider // using an ExecutorService object to serialize calls to Twitter. AsynchUtil.runAsynchronously(new Runnable() { public void run() { try { twitter.updateStatus(status); } catch (TwitterException e) { form.dispatchErrorOccurredEvent(Twitter.this, "Tweet", ErrorMessages.ERROR_TWITTER_SET_STATUS_FAILED, e.getMessage()); } } }); }