List of usage examples for twitter4j Status getInReplyToScreenName
String getInReplyToScreenName();
From source file:tweetcrawling.TweetCrawler.java
public void printTweets(String csvOut) throws IOException, TwitterException { for (Status status : getStatuses()) { // Getting the value to be written Long tid = status.getId(); String tweetid = tid.toString(); ArrayList<String> valueToWrite = new ArrayList<String>(); User user = status.getUser();// w w w. java 2 s. c o m String screenname = user.getScreenName(); String name = user.getName(); String url = getTweetUrl(screenname, tweetid); valueToWrite.add(url); // element: id valueToWrite.add(screenname); // element: userid valueToWrite.add(name); // element: user // element: gender if (name != null && !name.isEmpty()) { valueToWrite.add(getUserGender(name)); } else if (screenname != null && !screenname.isEmpty()) { valueToWrite.add(getUserGender(screenname)); } else { valueToWrite.add(""); } valueToWrite.add(user.getLocation()); // element: location valueToWrite.add("" + user.getFollowersCount()); // element: followercount valueToWrite.add("" + user.getFriendsCount()); // element: friendscount valueToWrite.add("" + user.getStatusesCount()); // element: statuscount try { List<String> coor = new ArrayList<String>(); String latitude = "" + status.getGeoLocation().getLatitude(); String longitude = "" + status.getGeoLocation().getLongitude(); coor.add(latitude); coor.add(longitude); if (coor != null && !coor.isEmpty() && coor.size() > 0) { valueToWrite.add(coor.get(0)); // element: latitude valueToWrite.add(coor.get(1)); // element: longitude valueToWrite.add(coor.get(0) + "," + coor.get(1)); } else { valueToWrite.add(null); valueToWrite.add(null); valueToWrite.add(null); } } catch (Exception e) { valueToWrite.add(null); valueToWrite.add(null); valueToWrite.add(null); } try { String geoname = status.getPlace().getName(); String country = status.getPlace().getCountry(); if (geoname != null) { valueToWrite.add(geoname); } else { valueToWrite.add(null); } if (country != null) { valueToWrite.add(country); } else { valueToWrite.add(null); } } catch (Exception e) { valueToWrite.add(null); valueToWrite.add(null); } DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); Date date = status.getCreatedAt(); valueToWrite.add(dateFormat.format(date)); // element: date valueToWrite.add(getDateCrawler()); // element: datecrawler valueToWrite.add(status.getText()); // element: body valueToWrite.add(status.getInReplyToScreenName()); // element: replyto String tooltip = ""; try { String geoname = status.getPlace().getName(); if (geoname != null) { tooltip = "user = " + name + ", geoname = " + geoname; } } catch (Exception e) { tooltip = ""; } valueToWrite.add(tooltip.trim()); // element: tooltip valueToWrite.add(SOURCE); // element: source // Write valueToWrite to csv external file FileWriter fw = new FileWriter(csvOut, true); PrintWriter pw = new PrintWriter(fw); String content = "'"; for (int i = 0; i < valueToWrite.size() - 1; i++) { content += valueToWrite.get(i) + "','"; } content += valueToWrite.get(valueToWrite.size()) + "'"; pw.print(content); pw.flush(); pw.close(); fw.close(); } }
From source file:twitbak.MentionBak.java
License:Open Source License
public void statusToJson(Status status) throws TwitterException, JSONException { JSONObject result = new JSONObject(); User poster = status.getUser();/*from ww w. j av a2 s .co m*/ result.put("Poster ID", poster.getId()); result.put("Poster", poster.getScreenName()); result.put("Poster Name", poster.getName()); result.put("Created At", status.getCreatedAt().toString()); result.put("ID", status.getId()); result.put("Text", status.getText()); long inReplyToStatusId = status.getInReplyToStatusId(); if (inReplyToStatusId != -1) { result.put("In Reply To Status ID", status.getInReplyToStatusId()); } long inReplyToUserID = status.getInReplyToUserId(); result.put("In Reply To User ID", inReplyToUserID); if (inReplyToUserID != -1) { result.put("In Reply To Screen Name", status.getInReplyToScreenName()); } boolean isFavorited = status.isFavorited(); if (isFavorited) { result.put("Favorited", status.isFavorited()); } statusArray().put(result); }
From source file:twitbak.StatusBak.java
License:Open Source License
/** * Adds a Status to statusArray as a JSONObject. * //from w ww . j a v a 2s.c om * @param status * @throws TwitterException * @throws JSONException */ public void statusToJson(Status status) throws TwitterException, JSONException { JSONObject result = new JSONObject(); result.put("Created At", status.getCreatedAt().toString()); result.put("ID", status.getId()); result.put("Text", status.getText()); long inReplyToStatusId = status.getInReplyToStatusId(); if (inReplyToStatusId != -1) { result.put("In Reply To Status ID", status.getInReplyToStatusId()); } long inReplyToUserID = status.getInReplyToUserId(); result.put("In Reply To User ID", inReplyToUserID); if (inReplyToUserID != -1) { result.put("In Reply To Screen Name", status.getInReplyToScreenName()); } boolean isFavorited = status.isFavorited(); if (isFavorited) { result.put("Favorited", status.isFavorited()); } statusArray.put(result); }
From source file:twitterapidemo.TwitterAPIDemo.java
License:Apache License
public static void main(String[] args) throws IOException, TwitterException { //TwitterAPIDemo twitterApiDemo = new TwitterAPIDemo(); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(consumerKey); builder.setOAuthConsumerSecret(consumerSecret); Configuration configuration = builder.build(); TwitterFactory twitterFactory = new TwitterFactory(configuration); Twitter twitter = twitterFactory.getInstance(); twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); Scanner sc = new Scanner(System.in); System.out.println(/*from ww w. j a v a 2s . c o m*/ "Enter your choice:\n1. To post tweet\n2.To search tweets\n3. Recent top 3 trends and number of posts of each trending topic"); int choice = sc.nextInt(); switch (choice) { case 1: System.out.println("What's happening: "); String post = sc.next(); StatusUpdate statusUpdate = new StatusUpdate(post + "-Posted by TwitterAPI"); Status status = twitter.updateStatus(statusUpdate); System.out.println("status.toString() = " + status.toString()); System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName()); System.out.println("status.getSource() = " + status.getSource()); System.out.println("status.getText() = " + status.getText()); System.out.println("status.getContributors() = " + Arrays.toString(status.getContributors())); System.out.println("status.getCreatedAt() = " + status.getCreatedAt()); System.out.println("status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId()); System.out.println("status.getGeoLocation() = " + status.getGeoLocation()); System.out.println("status.getId() = " + status.getId()); System.out.println("status.getInReplyToStatusId() = " + status.getInReplyToStatusId()); System.out.println("status.getInReplyToUserId() = " + status.getInReplyToUserId()); System.out.println("status.getPlace() = " + status.getPlace()); System.out.println("status.getRetweetCount() = " + status.getRetweetCount()); System.out.println("status.getRetweetedStatus() = " + status.getRetweetedStatus()); System.out.println("status.getUser() = " + status.getUser()); System.out.println("status.getAccessLevel() = " + status.getAccessLevel()); System.out.println("status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities())); System.out.println("status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities())); if (status.getRateLimitStatus() != null) { System.out.println( "status.getRateLimitStatus().getLimit() = " + status.getRateLimitStatus().getLimit()); System.out.println("status.getRateLimitStatus().getRemaining() = " + status.getRateLimitStatus().getRemaining()); System.out.println("status.getRateLimitStatus().getResetTimeInSeconds() = " + status.getRateLimitStatus().getResetTimeInSeconds()); System.out.println("status.getRateLimitStatus().getSecondsUntilReset() = " + status.getRateLimitStatus().getSecondsUntilReset()); } System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities())); System.out.println( "status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities())); break; case 2: System.out.println("Enter keyword"); String keyword = sc.next(); try { Query query = new Query(keyword); QueryResult result; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { System.out.println(tweet.getCreatedAt() + ":\t@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); } } while ((query = result.nextQuery()) != null); System.exit(0); } catch (TwitterException te) { System.out.println("Failed to search tweets: " + te.getMessage()); System.exit(-1); break; } case 3: //WOEID for India = 23424848 Trends trends = twitter.getPlaceTrends(23424848); int count = 0; for (Trend trend : trends.getTrends()) { if (count < 3) { Query query = new Query(trend.getName()); QueryResult result; int numberofpost = 0; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { numberofpost++; } } while ((query = result.nextQuery()) != null); System.out .println("Number of post for the topic '" + trend.getName() + "' is: " + numberofpost); count++; } else break; } break; default: System.out.println("Invalid input"); } }
From source file:twitterswingclient.TwitterClient.java
private void updateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateActionPerformed // TODO add your handling code here: String consKey = "Your key"; String consSecret = "Your secret"; String accToken = "Your key"; String accSecret = "Your secret"; try {/* ww w .jav a 2 s . c o m*/ TwitterFactory twitterFactory = new TwitterFactory(); Twitter twitter = twitterFactory.getInstance(); twitter.setOAuthConsumer(consKey, consSecret); twitter.setOAuthAccessToken(new AccessToken(accToken, accSecret)); StatusUpdate statusUpdate = new StatusUpdate(status.getText()); statusUpdate.setMedia("Feeling great", new URL("http://media3.giphy.com/media/el1tH0BzEWm4w/giphy.gif").openStream()); Status stat = twitter.updateStatus(statusUpdate); textArea.append("status.toString() = " + stat.toString()); textArea.append("status.getInReplyToScreenName() = " + stat.getInReplyToScreenName()); textArea.append("status.getSource() = " + stat.getSource()); textArea.append("status.getText() = " + stat.getText()); textArea.append("status.getContributors() = " + Arrays.toString(stat.getContributors())); textArea.append("status.getCreatedAt() = " + stat.getCreatedAt()); textArea.append("status.getCurrentUserRetweetId() = " + stat.getCurrentUserRetweetId()); textArea.append("status.getGeoLocation() = " + stat.getGeoLocation()); textArea.append("status.getId() = " + stat.getId()); textArea.append("status.getInReplyToStatusId() = " + stat.getInReplyToStatusId()); textArea.append("status.getInReplyToUserId() = " + stat.getInReplyToUserId()); textArea.append("status.getPlace() = " + stat.getPlace()); textArea.append("status.getRetweetCount() = " + stat.getRetweetCount()); textArea.append("status.getRetweetedStatus() = " + stat.getRetweetedStatus()); textArea.append("status.getUser() = " + stat.getUser()); textArea.append("status.getAccessLevel() = " + stat.getAccessLevel()); textArea.append("status.getHashtagEntities() = " + Arrays.toString(stat.getHashtagEntities())); textArea.append("status.getMediaEntities() = " + Arrays.toString(stat.getMediaEntities())); if (stat.getRateLimitStatus() != null) { textArea.append("status.getRateLimitStatus().getLimit() = " + stat.getRateLimitStatus().getLimit()); textArea.append( "status.getRateLimitStatus().getRemaining() = " + stat.getRateLimitStatus().getRemaining()); textArea.append("status.getRateLimitStatus().getResetTimeInSeconds() = " + stat.getRateLimitStatus().getResetTimeInSeconds()); textArea.append("status.getRateLimitStatus().getSecondsUntilReset() = " + stat.getRateLimitStatus().getSecondsUntilReset()); textArea.append("status.getRateLimitStatus().getRemainingHits() = " + stat.getRateLimitStatus().getRemaining()); } textArea.append("status.getURLEntities() = " + Arrays.toString(stat.getURLEntities())); textArea.append("status.getUserMentionEntities() = " + Arrays.toString(stat.getUserMentionEntities())); } catch (IOException ex) { textArea.append("IO Exception"); } catch (TwitterException tw) { textArea.append("Twitter Exception"); } }