List of usage examples for twitter4j TwitterException getMessage
@Override
public String getMessage()
From source file:twit.Twit.java
public void userMention() throws SQLException, ParseException { Twitter twitter = new TwitterFactory().getInstance(); try {/*w w w .ja v a 2 s. c om*/ Long since_id = cek_last_mention(); Paging paging = new Paging().sinceId(since_id); List<Status> statuses = twitter.getMentionsTimeline(paging); for (twitter4j.Status status : statuses) { long ID_TWEET = status.getId(); String USERNAME = status.getUser().getScreenName(); String TWEET = status.getText().replace("'", "\\'"); save_user(USERNAME); String ID_MASYARAKAT = cekMasyarakat(USERNAME); if (USERNAME.equals("tahupongcode")) { //reply akun sendiri save_data_mentions(ID_TWEET); } else { if (Regex(TWEET)[0].equals("harga")) { //masukkan hasil regex pada array String[] hasil = Regex(TWEET); //ambil isi array int KOMODITAS = cekKomoditas(hasil[2]); String TITIK_DISTRIBUSI = cekTitik(hasil[3]); String HARGA = hasil[4]; save_harga(KOMODITAS, TITIK_DISTRIBUSI, ID_MASYARAKAT, USERNAME, HARGA); if (cek_replied(ID_TWEET) == false) { save_data_mentions(ID_TWEET); onStatus(status, 1); } } else if (Regex(TWEET)[0].equals("keluhan")) { //masukkan hasil regex pada array String[] hasil = Regex(TWEET); //ambil isi array String SUBJECT = hasil[2]; String KELUHAN = hasil[3]; String KABUPATEN = cekKabupaten(hasil[4]); insertKeluhan(ID_MASYARAKAT, SUBJECT, KELUHAN, KABUPATEN); if (cek_replied(ID_TWEET) == false) { save_data_mentions(ID_TWEET); onStatus(status, 2); } } else { System.out.println("error"); } } } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
From source file:twit.TwitterConnector.java
/** * Mencari tweet yang mengandung keyword tertentu * @param n merupakan jumlah tweet terbaru * @param keyword merupakan kata kunci yang ingin dicari * @return List yang mengandung keyword/*from w w w. j ava2s . c o m*/ */ public List<Status> searchKeyword(int n, String keyword) { try { query = new Query(keyword); query.setCount(n); QueryResult result; result = twitter.search(query); tweets = result.getTweets(); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); } return tweets; }
From source file:twitter.botframework.connector.TwitterBotframeworkConnector.java
public static void GetDirectMessage(Twitter twitter) throws ApiException, InterruptedException { //Twitter twitter = new TwitterFactory().getInstance(); try {//w ww .j av a2 s .c o m Paging paging = new Paging(1); List<DirectMessage> messages; do { messages = twitter.getDirectMessages(paging); for (DirectMessage message : messages) { System.out.println("From: @" + message.getSenderScreenName() + " id:" + message.getId() + " - " + message.getText()); user_name = user_name.concat(message.getSenderScreenName()); user_message = message.getText(); //send a tweet //Status status = twitter.updateStatus("Hola " +user_name +" Estamos atendiendo tu peticion! #Fintechando #HaciendoElParo"); DirectLineToBot(user_name, user_message); SendDirectMessageAsResponse(twitter); } paging.setPage(paging.getPage() + 1); } while (messages.size() > 0 && paging.getPage() < 10); /*System.out.println("done."); System.exit(0);*/ } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get messages: " + te.getMessage()); } catch (ApiException te) { te.printStackTrace(); System.out.println("Failed to get messages: " + te.getMessage()); } }
From source file:twitter.botframework.connector.TwitterBotframeworkConnector.java
public static void SendDirectMessageAsResponse(Twitter twitter) { //Twitter twitter = new TwitterFactory().getInstance(); try {//w ww . java 2 s . c o m DirectMessage message = twitter.sendDirectMessage(user_name, user_message); 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:twitter.crawler.TwitterCrawler.java
public static void main(String[] args) { try {//from w w w .j a v a 2 s . com // Authorise the library ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey("AhoydO8uSe4v8NEq7j2ISGFlq"); cb.setOAuthConsumerSecret("ptKEYwq3G9vpFkqAhvwFLSWFcBW8U1SfqycECwK4cH6wThVba6"); cb.setOAuthAccessToken("778240255577194496-taafqDIHebrg972oxT5kTqcNd3Uojod"); cb.setOAuthAccessTokenSecret("DMRmeRahnLJRvCBIGQGTaTzE6Pr3PAZMgMsfWIT5ue3PD"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); User user = twitter.verifyCredentials(); // Get main user long cursor = -1; // Print user profile System.out.println("@" + user.getScreenName()); System.out.println(user.getId()); System.out.println(user.getProfileImageURL()); System.out.println(user.getFriendsCount() + " friends."); System.out.println("-------"); // Print Home Timeline List<Status> statuses = twitter.getHomeTimeline(); System.out.println("Showing @" + user.getScreenName() + "'s home timeline."); for (Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } //Print followers System.out.println("-------"); System.out.println("Showing Follwers:"); PagableResponseList<User> followers; //do //{ followers = twitter.getFollowersList(user.getScreenName(), cursor); for (User follower : followers) { System.out.println("@" + follower.getScreenName()); } //} //while ((cursor = followers.getNextCursor())!=-1); //Print follwees System.out.println("-------"); System.out.println("Showing Followees:"); PagableResponseList<User> followees; do { followees = twitter.getFriendsList(user.getScreenName(), cursor); for (User followee : followees) { System.out.println("@" + followee.getScreenName()); } } while ((cursor = followees.getNextCursor()) != -1); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
From source file:twitter.sample.GetAccessToken.java
License:Apache License
/** * Usage: java twitter4j.examples.oauth.GetAccessToken [consumer key] [consumer secret] * * @param args message/* w ww . j a v a 2 s . co m*/ */ public static void main(String[] args) { File file = new File("twitter4j.properties"); Properties prop = new Properties(); InputStream is = null; OutputStream os = null; try { if (file.exists()) { is = new FileInputStream(file); prop.load(is); } if (args.length < 2) { if (null == prop.getProperty("oauth.consumerKey") && null == prop.getProperty("oauth.consumerSecret")) { // consumer key/secret are not set in twitter4j-bak.properties System.out.println( "Usage: java twitter4j.examples.oauth.GetAccessToken [consumer key] [consumer secret]"); System.exit(-1); } } else { prop.setProperty("oauth.consumerKey", args[0]); prop.setProperty("oauth.consumerSecret", args[1]); os = new FileOutputStream("twitter4j.properties"); prop.store(os, "twitter4j.properties"); } } catch (IOException ioe) { ioe.printStackTrace(); System.exit(-1); } finally { if (is != null) { try { is.close(); } catch (IOException ignore) { } } if (os != null) { try { os.close(); } catch (IOException ignore) { } } } try { Twitter twitter = new TwitterFactory().getInstance(); 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()); try { Desktop.getDesktop().browse(new URI(requestToken.getAuthorizationURL())); } catch (UnsupportedOperationException ignore) { } catch (IOException ignore) { } catch (URISyntaxException e) { throw new AssertionError(e); } 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()); try { prop.setProperty("oauth.accessToken", accessToken.getToken()); prop.setProperty("oauth.accessTokenSecret", accessToken.getTokenSecret()); os = new FileOutputStream(file); prop.store(os, "twitter4j.properties"); os.close(); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(-1); } finally { if (os != null) { try { os.close(); } catch (IOException ignore) { } } } System.out.println("Successfully stored access token to " + file.getAbsolutePath() + "."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get accessToken: " + 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:twitter.TweetGet.java
public void query(String queryString) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("2MZnm7LM7Ik9W3hzcXJOBaNER") .setOAuthConsumerSecret("0GER2kH3o1gOAyfPEDd870Iiuiu6XbQDayAXWfUBxU5APg4Le6") .setOAuthAccessToken("18972247-HgBP0djVaLw4U9fSX4lUdhKpZcqsJIAgnUCW3DRS5") .setOAuthAccessTokenSecret("bn8EQoOyGSRVUNX6elTmX9Wt9jiFJaxDaCZDk3U3hQB0g"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); Query query = new Query(queryString); query.setCount(20);//from ww w .j a v a2 s .com QueryResult result; try { result = twitter.search(query); tweets = result.getTweets(); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); } }
From source file:twitter.TweetGet.java
public void getTweetFromUser(String username) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("2MZnm7LM7Ik9W3hzcXJOBaNER") .setOAuthConsumerSecret("0GER2kH3o1gOAyfPEDd870Iiuiu6XbQDayAXWfUBxU5APg4Le6") .setOAuthAccessToken("18972247-HgBP0djVaLw4U9fSX4lUdhKpZcqsJIAgnUCW3DRS5") .setOAuthAccessTokenSecret("bn8EQoOyGSRVUNX6elTmX9Wt9jiFJaxDaCZDk3U3hQB0g"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); try {//from w w w.ja v a 2s. c om tweets = twitter.getUserTimeline(username); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); } }
From source file:twitter4j.examples.account.GetAccountSettings.java
License:Apache License
/** * Usage: java twitter4j.examples.account.GetAccountSettings * * @param args arguments doesn't take effect with this example *//*from w w w . ja v a2 s. com*/ public static void main(String[] args) { try { Twitter twitter = new TwitterFactory().getInstance(); AccountSettings settings = twitter.getAccountSettings(); System.out.println("Sleep time enabled: " + settings.isSleepTimeEnabled()); System.out.println("Sleep end time: " + settings.getSleepEndTime()); System.out.println("Sleep start time: " + settings.getSleepStartTime()); System.out.println("Geo enabled: " + settings.isGeoEnabled()); System.out.println("Screen name: " + settings.getScreenName()); System.out.println("Listing trend locations:"); Location[] locations = settings.getTrendLocations(); for (Location location : locations) { System.out.println(" " + location.getName()); } System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get account settings: " + te.getMessage()); System.exit(-1); } }
From source file:twitter4j.examples.account.GetRateLimitStatus.java
License:Apache License
/** * Usage: java twitter4j.examples.account.GetRateLimitStatus * * @param args message// ww w . ja v a 2 s.c o m */ public static void main(String[] args) { try { Twitter twitter = new TwitterFactory().getInstance(); Map<String, RateLimitStatus> rateLimitStatus = twitter.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); } }