List of usage examples for twitter4j User getFollowersCount
int getFollowersCount();
From source file:TwitterStats.Facade.Twitter.java
public Map<String, Double> getRepercusionCuentas(List<String> cuentas) throws TwitterException { Map<String, Double> map = new HashMap<>(); for (int j = 0; j < cuentas.size(); j++) { List<User> users = twitter.getFollowersList(cuentas.get(j).substring(1, cuentas.get(j).length()), -1, 50);/*from w w w .ja v a 2 s. c o m*/ map.put(cuentas.get(j), (double) twitter .getFollowersIDs(cuentas.get(j).substring(1, cuentas.get(j).length()), -1).getIDs().length); for (User user : users) { map.put(cuentas.get(j), map.get(cuentas.get(j)) + user.getFollowersCount()); } } double total = 0; for (Map.Entry<String, Double> entry : map.entrySet()) { System.out.println(entry.getValue()); total = total + (double) entry.getValue(); } for (String key : map.keySet()) { map.put(key, (map.get(key) * 100) / total); } return map; }
From source file:uk.ac.susx.tag.method51.twitter.Tweet.java
License:Apache License
public Tweet(Status status) { this();/*from ww w.j a v a 2s .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.ac.susx.tag.method51.webapp.handler.TwitterPinAuthHandler.java
License:Apache License
private void getUserInfo(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { final Params params = new Params(); params.addValidator("id", new SystemStringValidator(true)); new DoSomethingAfterValidatingMyParams(params, request, response) { @Override//w ww.j a v a 2s . c o m public void something() throws IOException { final String id = request.getParameter("id"); final Twitter twitter = newTwitterInstance(ApiKeyStore.getKey(id)); try { final AccountSettings as = twitter.getAccountSettings(); final String userScreenName = twitter.getScreenName(); final long userId = twitter.getId(); final User user = twitter.showUser(userId); okHereIsYourJson(response, "name", user.getName(), "description", user.getDescription(), "created", user.getCreatedAt(), "favourites_count", user.getFavouritesCount(), "followers_count", user.getFollowersCount(), "friends_count", user.getFriendsCount(), "profile_image_url", user.getProfileImageURL(), "screen_name", userScreenName, "user_id", userId, "language", as.getLanguage(), "sleep_time_enabled", as.isSleepTimeEnabled(), "sleep_end_time", as.getSleepEndTime(), "sleep_start_time", as.getSleepStartTime(), "timezone", as.getTimeZone(), "trend_locations", as.getTrendLocations(), "always_use_https", as.isAlwaysUseHttps(), "discoverable_by_email", as.isDiscoverableByEmail(), "geo_enabled", as.isGeoEnabled()); } catch (TwitterException e) { LOG.warn("Failed to retrieve users data.", e); error(e.getMessage()); } } }; }
From source file:uk.co.cathtanconsulting.twitter.TwitterSource.java
License:Apache License
/** * @param status//from w ww . ja v a 2 s. c o m * * Generate a TweetRecord object and submit to * */ private void extractRecord(Status status) { TweetRecord record = new TweetRecord(); //Basic attributes record.setId(status.getId()); //Using SimpleDateFormat "yyyy-MM-dd'T'HH:mm:ss'Z'" record.setCreatedAtStr(formatterTo.format(status.getCreatedAt())); //Use millis since epoch since Avro doesn't do dates record.setCreatedAtLong(status.getCreatedAt().getTime()); record.setTweet(status.getText()); //User based attributes - denormalized to keep the Source stateless //but also so that we can see user attributes changing over time. //N.B. we could of course fork this off as a separate stream of user info User user = status.getUser(); record.setUserId(user.getId()); record.setUserScreenName(user.getScreenName()); record.setUserFollowersCount(user.getFollowersCount()); record.setUserFriendsCount(user.getFriendsCount()); record.setUserLocation(user.getLocation()); //If it is zero then leave the value null if (status.getInReplyToStatusId() != 0) { record.setInReplyToStatusId(status.getInReplyToStatusId()); } //If it is zero then leave the value null if (status.getInReplyToUserId() != 0) { record.setInReplyToUserId(status.getInReplyToUserId()); } //Do geo. N.B. Twitter4J doesn't give use the geo type GeoLocation geo = status.getGeoLocation(); if (geo != null) { record.setGeoLat(geo.getLatitude()); record.setGeoLong(geo.getLongitude()); } //If a status is a retweet then the original tweet gets bundled in //Because we can't guarantee that we'll have the original we can //extract the original tweet and process it as we have done this time //using recursion. Note: we will end up with dupes. Status retweetedStatus = status.getRetweetedStatus(); if (retweetedStatus != null) { record.setRetweetedStatusId(retweetedStatus.getId()); record.setRetweetedUserId(retweetedStatus.getUser().getId()); extractRecord(retweetedStatus); } //Submit the populated record onto the channel processRecord(record); }
From source file:Utils.ConvertUsers.java
License:Open Source License
public Set<TwitterUser> convertAll(Set<User> users) { Set<TwitterUser> twitterUsers = new HashSet(); TwitterUser twitterUser;//from ww w. j a v a2s . c o m for (User user : users) { twitterUser = new TwitterUser(); twitterUser.setCreated_at(user.getCreatedAt()); twitterUser.setDescription(user.getDescription()); twitterUser.setFollowers_count(user.getFollowersCount()); twitterUser.setLang(user.getLang()); twitterUser.setLocation(user.getLocation()); twitterUser.setName(user.getName()); twitterUser.setProfile_image_url(user.getProfileImageURL()); twitterUser.setScreen_name(user.getScreenName()); twitterUser.setIdTwitter(user.getId()); twitterUser.setFriends_count(user.getFriendsCount()); twitterUser.setProfile_banner_url(user.getProfileBannerURL()); twitterUsers.add(twitterUser); } return twitterUsers; }
From source file:Utils.ConvertUsers.java
License:Open Source License
public TwitterUser convertOne(User user) { TwitterUser twitterUser;//from www. j a v a 2 s . com twitterUser = new TwitterUser(); twitterUser.setCreated_at(user.getCreatedAt()); twitterUser.setDescription(user.getDescription()); twitterUser.setFollowers_count(user.getFollowersCount()); twitterUser.setLang(user.getLang()); twitterUser.setLocation(user.getLocation()); twitterUser.setName(user.getName()); twitterUser.setProfile_image_url(user.getProfileImageURL()); twitterUser.setScreen_name(user.getScreenName()); twitterUser.setIdTwitter(user.getId()); twitterUser.setFriends_count(user.getFriendsCount()); twitterUser.setProfile_banner_url(user.getProfileBannerURL()); return twitterUser; }