List of usage examples for twitter4j Status getPlace
Place getPlace();
From source file:twitterrest.GeoSearch.java
License:Apache License
public static void main(String[] args) throws TwitterException { // ?//ww w . jav a 2 s . c o m Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY) .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN) .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build(); Twitter twitter = new TwitterFactory(configuration).getInstance(); Query query = new Query(); // ?????10kmIP?????? GeoLocation geo = new GeoLocation(35.69384, 139.703549); query.setGeoCode(geo, 10.0, Query.KILOMETERS); // QueryResult result = twitter.search(query); // ???Tweet??placegeoLocation?????? for (Status tweet : result.getTweets()) { System.out.println(tweet.getText()); System.out.println(tweet.getPlace() + " : " + tweet.getGeoLocation()); } }
From source file:twittersentimentanalysis.TwitterSentimentAnalysis.java
private static Tweet getTweetObject(Status status) { Tweet tweet = new Tweet(); int sentimentScore = StanfordCoreNLPTool.findSentiment(status.getText()); if (sentimentScore != -1) { tweet.setDateTime(status.getCreatedAt()); tweet.setTweetText(status.getText()); tweet.setUsername(status.getUser().getScreenName()); tweet.setSentimentScore(sentimentScore); GeoLocation geoLocation = status.getGeoLocation(); if (geoLocation != null) { tweet.setLongitude(geoLocation.getLongitude() + ""); tweet.setLatitude(geoLocation.getLatitude() + ""); } else {// w w w .j av a 2 s . c om tweet.setLongitude(null);// tweet.setLatitude(null);// } Place place = status.getPlace(); if (place != null) { tweet.setCountry(place.getCountry()); tweet.setPlace(place.getFullName()); } else { tweet.setCountry(null);// tweet.setPlace(null);// } } else tweet = null; return tweet; }
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 {//from ww w. j ava 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"); } }
From source file:uk.ac.susx.tag.method51.twitter.Tweet.java
License:Apache License
public Tweet(Status status) { this();// w w w .j a v a 2 s .c o m created = status.getCreatedAt(); id = status.getId(); text = status.getText(); inReplyToStatusId = status.getInReplyToStatusId(); inReplyToUserId = status.getInReplyToUserId(); originalText = null; retweetId = -1; isTruncated = status.isTruncated(); isRetweet = status.isRetweet(); Status entities = status; if (isRetweet) { Status origTweet = status.getRetweetedStatus(); entities = origTweet; retweetId = origTweet.getId(); originalText = text; text = origTweet.getText(); } StringBuilder sb = new StringBuilder(); for (HashtagEntity e : entities.getHashtagEntities()) { sb.append(e.getText()); sb.append(" "); } hashtags = sb.toString(); sb = new StringBuilder(); for (UserMentionEntity e : entities.getUserMentionEntities()) { sb.append(e.getScreenName()); sb.append(" "); } mentions = sb.toString(); sb = new StringBuilder(); for (URLEntity e : entities.getURLEntities()) { //String url = e.getURL(); String url = e.getExpandedURL(); if (url == null) { url = e.getURL(); if (url != null) { sb.append(url); } } else { sb.append(url); } sb.append(" "); } urls = sb.toString(); sb = new StringBuilder(); //seems to be null if no entries MediaEntity[] mediaEntities = entities.getMediaEntities(); if (mediaEntities != null) { for (MediaEntity e : mediaEntities) { String url = e.getMediaURL(); sb.append(url); sb.append(" "); } mediaUrls = sb.toString(); } else { mediaUrls = ""; } received = new Date(); source = status.getSource(); GeoLocation geoLoc = status.getGeoLocation(); Place place = status.getPlace(); if (geoLoc != null) { geoLong = geoLoc.getLongitude(); geoLat = geoLoc.getLatitude(); } else if (place != null && place.getBoundingBoxCoordinates() != null && place.getBoundingBoxCoordinates().length > 0) { GeoLocation[] locs = place.getBoundingBoxCoordinates()[0]; double avgLat = 0; double avgLon = 0; for (GeoLocation loc : locs) { avgLat += loc.getLatitude(); avgLon += loc.getLongitude(); } avgLat /= locs.length; avgLon /= locs.length; geoLat = avgLat; geoLong = avgLon; } else { geoLong = null; geoLat = null; } twitter4j.User user = status.getUser(); if (user != null) { userId = user.getId(); location = user.getLocation(); screenName = user.getScreenName(); following = user.getFriendsCount(); name = user.getName(); lang = user.getLang(); timezone = user.getTimeZone(); userCreated = user.getCreatedAt(); followers = user.getFollowersCount(); statusCount = user.getStatusesCount(); description = user.getDescription(); url = user.getURL(); utcOffset = user.getUtcOffset(); favouritesCount = user.getFavouritesCount(); this.user = new User(user); } }
From source file:uk.co.flax.ukmp.twitter.TweetUpdateThread.java
License:Apache License
private Tweet buildTweetFromStatus(Status status) { String text = status.getText(); Tweet tweet = new Tweet(); tweet.setId("" + status.getId()); tweet.setText(text);//from w ww . j av a2 s . c o m tweet.setUserScreenName(status.getUser().getScreenName()); tweet.setUserName(status.getUser().getName()); tweet.setCreated(status.getCreatedAt()); if (status.getPlace() != null) { tweet.setPlaceName(status.getPlace().getFullName()); tweet.setCountry(status.getPlace().getCountry()); } tweet.setRetweetCount(status.getRetweetCount()); tweet.setFavouriteCount(status.getFavoriteCount()); tweet.setParty(partyListIds.get(status.getUser().getId())); if (status.getUserMentionEntities() != null) { List<String> screenNames = new ArrayList<>(status.getUserMentionEntities().length); List<String> fullNames = new ArrayList<>(status.getUserMentionEntities().length); for (UserMentionEntity ent : status.getUserMentionEntities()) { screenNames.add(ent.getScreenName()); if (StringUtils.isNotBlank(ent.getName())) { fullNames.add(ent.getName()); } } tweet.setMentionScreenNames(screenNames); tweet.setMentionFullNames(fullNames); } if (status.getHashtagEntities().length > 0) { List<String> hashtags = new ArrayList<>(status.getHashtagEntities().length); for (HashtagEntity ht : status.getHashtagEntities()) { hashtags.add(ht.getText()); } tweet.setHashtags(hashtags); } // Call the entity extraction service Map<String, List<String>> entities = entityExtraction.getEntities(text); if (entities != null && !entities.isEmpty()) { Map<String, Object> tweetEntities = new HashMap<String, Object>(); entities.keySet().forEach(type -> tweetEntities.put(type, entities.get(type))); tweet.setEntities(tweetEntities); } return tweet; }