List of usage examples for twitter4j User getLocation
String getLocation();
From source file:uk.co.cathtanconsulting.twitter.TwitterSource.java
License:Apache License
/** * @param status//w w w .ja v a 2 s. c om * * 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:User.SearchUsers.java
License:Apache License
public String[] getResults(String name) { try {/*from www . jav a 2s. co m*/ Twitter twitter = builder.twitter; int page = 1; int i = 0; ResponseList<User> users; String[] persons = new String[100]; do { users = twitter.searchUsers(name, page); for (User user : users) { String str = ""; if (user != null) { if (user.getName() != null && !user.getName().equals("null") && !user.getName().equals("")) { str = str + user.getName() + ";"; System.out.println(user.getName()); if (user.getLocation() != null) { str = str + user.getLocation() + ";"; } else { str = str + "N/A;"; } if (user.getMiniProfileImageURL() != null) { str = str + user.getProfileImageURL(); } else { str = str + "N/A"; } persons[i] = str; i++; } } } page++; } while (users.size() != 0 && page < 2); return persons; } catch (TwitterException te) { te.printStackTrace(); } return null; }
From source file:Utils.ConvertUsers.java
License:Open Source License
public Set<TwitterUser> convertAll(Set<User> users) { Set<TwitterUser> twitterUsers = new HashSet(); TwitterUser twitterUser;/*w w w. j a va 2s . co 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 w w w . j a v a 2 s . c om*/ 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; }