List of usage examples for twitter4j Status getURLEntities
URLEntity[] getURLEntities();
From source file:uk.ac.susx.tag.method51.twitter.Tweet.java
License:Apache License
public Tweet(Status status) { this();//from ww w . ja 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:wise.TwitterUtils.java
public ArrayList<CheckinObject> dataList(String cityCode, String selectedDate, String maxTweetParam, String topTweetParam) throws IOException, JSONException, ParseException { ArrayList<CheckinObject> checkinList = new ArrayList<>(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(Constants.CONSUMER_KEY) .setOAuthConsumerSecret(Constants.CONSUMER_SECRET).setOAuthAccessToken(Constants.TOKEN) .setOAuthAccessTokenSecret(Constants.TOKEN_SECRET); Integer maxTweet = Integer.parseInt(maxTweetParam); Integer topTweet = Integer.parseInt(topTweetParam); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();/* ww w. jav a2 s . c o m*/ DateFormat format = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH); Date startDate = format.parse(selectedDate); Calendar c = Calendar.getInstance(); c.setTime(startDate); c.add(Calendar.DATE, 1); Date endDate = c.getTime(); Query query = SetQueryString(cityCode, startDate, endDate); QueryResult result = null; try { while (query != null && checkinList.size() <= maxTweet) { result = twitter.search(query); if (result != null) { for (Status status : result.getTweets()) { for (URLEntity urlEntity : status.getURLEntities()) { String urlCheckinId = urlEntity.getExpandedURL() .substring(urlEntity.getExpandedURL().lastIndexOf("/") + 1); GeoLocation geo = status.getGeoLocation(); CheckinObject checkin = new CheckinObject(); checkin.CheckinId = urlCheckinId; checkin.Count = 1;//status.getRetweetCount() + status.getFavoriteCount() + 1; checkin.Latitude = geo.getLatitude(); checkin.Longitude = geo.getLongitude(); if (!checkin.containsSameCoordinates(checkinList, checkin.Latitude, checkin.Longitude)) { checkinList.add(checkin); } else { int indexOfCheckinId = checkin.getIndexByCoordinates(checkinList, checkin.Latitude, checkin.Longitude); checkinList.get(indexOfCheckinId).setCheckinCount(checkin.Count); checkinList.get(indexOfCheckinId).setReplacementCheckinId(checkin.CheckinId); } } } query = result.nextQuery(); } else { query = null; } } } catch (TwitterException e) { } Collections.sort(checkinList, new CountComparator()); if (checkinList.size() > topTweet) { checkinList.subList(topTweet, checkinList.size()).clear(); // get top x } FourSquareCheckin fsq = new FourSquareCheckin(); for (CheckinObject checkin : checkinList) { fsq = getVenueInfo(checkin); checkin.LocationName = fsq.VenueName; checkin.Image = fsq.VenueImage; } return checkinList; }