List of usage examples for twitter4j TwitterException getMessage
@Override
public String getMessage()
From source file:com.javielinux.api.loaders.LoadTranslateTweetLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {/*from w w w.j a v a2s .c o m*/ LoadTranslateTweetResponse response = new LoadTranslateTweetResponse(); String lang = request.getLanguage(); Translate.setKey("2EFDAEA6BE06919111E8FA1FB505BF7A2FC6161B"); Language language = Language.ENGLISH; if (lang.equals("en")) { language = Language.ENGLISH; } else if (lang.equals("es")) { language = Language.SPANISH; } else if (lang.equals("fr")) { language = Language.FRENCH; } else if (lang.equals("de")) { language = Language.GERMAN; } else if (lang.equals("ja")) { language = Language.JAPANESE; } else if (lang.equals("pt")) { language = Language.PORTUGUESE; } else if (lang.equals("it")) { language = Language.ITALIAN; } else if (lang.equals("ru")) { language = Language.RUSSIAN; } else if (lang.equals("id")) { language = Language.INDONESIAN; } response.setText(Translate.execute(request.getText(), language)); return response; } catch (TwitterException twitterException) { twitterException.printStackTrace(); ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setError(twitterException, twitterException.getMessage()); return errorResponse; } catch (Exception exception) { exception.printStackTrace(); ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setError(exception, exception.getMessage()); return errorResponse; } }
From source file:com.javielinux.api.loaders.LoadTypeStatusLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {//from ww w .j a v a 2 s.co m LoadTypeStatusResponse response = new LoadTypeStatusResponse(); ArrayList<InfoTweet> result = new ArrayList<InfoTweet>(); ConnectionManager.getInstance().open(getContext()); if (request.getType() == FAVORITES) { ResponseList<Status> statii = ConnectionManager.getInstance().getTwitter(request.getUserId()) .getFavorites(); for (int i = 0; i < statii.size(); i++) { result.add(new InfoTweet(statii.get(i))); } } else if (request.getType() == SEARCH_USERS) { ResponseList<User> users = ConnectionManager.getInstance().getTwitter(request.getUserId()) .searchUsers(request.getUserSearchText(), 0); for (User user : users) { InfoTweet row = new InfoTweet(user); result.add(row); } } else if (request.getType() == RETWEETED_BYME) { // TODO retweet // ResponseList<Status> statii = ConnectionManager.getInstance().getTwitter(request.getUserId()).getRetweetedByMe(); // // for (int i=0; i<statii.size(); i++) { // result.add(new InfoTweet(statii.get(i))); // } } else if (request.getType() == RETWEETED_TOME) { // TODO retweet // ResponseList<Status> statii = ConnectionManager.getInstance().getTwitter(request.getUserId()).getRetweetedToMe(); // // for (int i=0; i<statii.size(); i++) { // result.add(new InfoTweet(statii.get(i))); // } } else if (request.getType() == RETWEETED_OFME) { ResponseList<Status> statii = ConnectionManager.getInstance().getTwitter(request.getUserId()) .getRetweetsOfMe(); for (int i = 0; i < statii.size(); i++) { result.add(new InfoTweet(statii.get(i))); } } else if (request.getType() == FOLLOWERS) { ResponseList<User> users = ConnectionManager.getInstance().getUserForSearchesTwitter() .lookupUsers(request.getUserIdList()); for (User user : users) { InfoTweet row = new InfoTweet(user); result.add(row); } } else if (request.getType() == FRIENDS) { ResponseList<User> users = ConnectionManager.getInstance().getUserForSearchesTwitter() .lookupUsers(request.getUserIdList()); for (User user : users) { InfoTweet row = new InfoTweet(user); result.add(row); } } else if (request.getType() == TIMELINE) { ResponseList<twitter4j.Status> statii = ConnectionManager.getInstance() .getTwitter(request.getUserId()).getHomeTimeline(); for (int i = 0; i < statii.size(); i++) { result.add(new InfoTweet(statii.get(i))); } } else if (request.getType() == LIST) { ResponseList<twitter4j.Status> statii; if (request.getUserId() < 0) { statii = ConnectionManager.getInstance().getUserForSearchesTwitter() .getUserListStatuses(request.getListId(), new Paging(1)); } else { statii = ConnectionManager.getInstance().getTwitter(request.getUserId()) .getUserListStatuses(request.getListId(), new Paging(1)); } for (int i = 0; i < statii.size(); i++) { result.add(new InfoTweet(statii.get(i))); } } else if (request.getType() == USER_TIMELINE) { ResponseList<twitter4j.Status> statii = ConnectionManager.getInstance().getUserForSearchesTwitter() .getUserTimeline(request.getUser()); for (int i = 0; i < statii.size(); i++) { result.add(new InfoTweet(statii.get(i))); } } response.setInfoTweets(result); return response; } catch (TwitterException e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } catch (OutOfMemoryError e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } catch (Exception e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } }
From source file:com.javielinux.api.loaders.LoadUserLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {// ww w .j av a2 s . com LoadUserResponse response = new LoadUserResponse(); ConnectionManager.getInstance().open(getContext()); User user_data = ConnectionManager.getInstance().getUserForSearchesTwitter() .showUser(request.getUser()); InfoUsers infoUsers = new InfoUsers(user_data); response.setInfoUsers(infoUsers); CacheData.getInstance().addCacheUsers(infoUsers); return response; } catch (TwitterException e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } catch (NullPointerException e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } catch (Exception e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } }
From source file:com.javielinux.api.loaders.RetweetStatusLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { //TODO: Comprobar el valor devuelto con el valor esperado (error - ready) try {//from ww w. ja v a 2 s .co m RetweetStatusResponse response = new RetweetStatusResponse(); ConnectionManager.getInstance().open(getContext()); ConnectionManager.getInstance().getTwitter(request.getUserId()).retweetStatus(request.getId()); response.setReady(true); return response; } catch (TwitterException e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } }
From source file:com.javielinux.api.loaders.StatusRetweetersLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {//from w ww .java 2s. c om // TODO retweet ConnectionManager.getInstance().open(getContext()); ResponseList<Status> retweeters_list = ConnectionManager.getInstance().getTwitter(request.getUserId()) .getRetweets(request.getId()); StatusRetweetersResponse response = new StatusRetweetersResponse(); //response.setUserList(retweeters_list); return response; } catch (TwitterException e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } }
From source file:com.javielinux.api.loaders.TrendsLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {//from ww w . j a va2s. co m ConnectionManager.getInstance().open(getContext()); TrendsResponse response = new TrendsResponse(); Trend[] trends_list = ConnectionManager.getInstance().getUserForSearchesTwitter() .getPlaceTrends(location_id).getTrends(); response.setTrends(new ArrayList<Trend>(Arrays.asList(trends_list))); return response; } catch (TwitterException e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } }
From source file:com.javielinux.api.loaders.TrendsLocationLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {/*from ww w . j av a 2 s . c o m*/ TrendsLocationResponse response = new TrendsLocationResponse(); ConnectionManager.getInstance().open(getContext()); response.setLocationList( ConnectionManager.getInstance().getUserForSearchesTwitter().getAvailableTrends()); return response; } catch (TwitterException e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } }
From source file:com.javielinux.api.loaders.UserListsLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {//from w w w .j av a2 s . com UserListsResponse response = new UserListsResponse(); ConnectionManager.getInstance().open(getContext()); response.action = request.getAction(); response.addUser = request.getAddUser(); if (request.getAction() == SHOW_TWEETS) { response.setUserList(ConnectionManager.getInstance().getUserForSearchesTwitter() .getUserLists(request.getUser())); } else if (request.getAction() == SHOW_TWEETS_FOLLOWINGLIST) { response.setUserList(ConnectionManager.getInstance().getUserForSearchesTwitter() .getUserListMemberships(request.getUser(), -1)); } else { ResponseList<UserList> responseList = ConnectionManager.getInstance().getUserForSearchesTwitter() .getUserLists(request.getUser()); ArrayList<UserList> deleteList = new ArrayList<UserList>(); for (UserList ul : responseList) { if (ul.isFollowing()) deleteList.add(ul); } responseList.removeAll(deleteList); response.setUserList(responseList); } return response; } catch (TwitterException e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } }
From source file:com.jetbrains.twitter.MessageSender.java
public static void sendDirectMessage(final Twitter twitter, final String recipient, final String text) { try {// ww w .j a v a 2 s .c o m final DirectMessage message = twitter.sendDirectMessage(recipient, text); System.out.println("Direct message successfully sent to " + message.getRecipientScreenName()); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to send a direct message: " + te.getMessage()); System.exit(-1); } }
From source file:com.klinker.android.twitter.services.MentionsRefreshService.java
License:Apache License
@Override public void onHandleIntent(Intent intent) { sharedPrefs = getSharedPreferences("com.klinker.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 w w w. j a v a2 s .c om*/ } 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()); } }