List of usage examples for twitter4j Status getUser
User getUser();
From source file:net.nokok.twitduke.core.twitter.LambdaTwitterStream.java
License:Open Source License
public void onStatusScreenName(Event<String> s) { this.twitterStream.addListener(new StatusAdapter() { @Override/*from w w w .j a v a2 s . com*/ public void onStatus(Status status) { s.onEvent(status.getUser().getScreenName()); } }); }
From source file:net.nokok.twitduke.core.twitter.PrintUserStreamListener.java
License:Open Source License
@Override public void onStatus(Status status) { System.out.println("onStatus: " + status.getUser().getScreenName() + "," + status.getText()); }
From source file:net.nokok.twitduke.core.type.TweetModel.java
License:Open Source License
public TweetModel(Status status) { User user = status.getUser(); this.screenName = new ScreenName(status.getUser().getScreenName()); if (status.getRetweetedStatus() != null) { this.retweetedStatus = Optional.of(new TweetModel(status.getRetweetedStatus())); } else {//w ww .j a v a 2 s . com this.retweetedStatus = Optional.empty(); } }
From source file:net.nokok.twitduke.core.view.async.OverlayUserIcon.java
License:Open Source License
private String getProfileImageUrl(Status status) { return status.getUser().getProfileImageURLHttps(); }
From source file:nl.b3p.viewer.stripes.TwitterActionBean.java
License:Open Source License
public Resolution create() throws JSONException { JSONObject json = new JSONObject(); json.put("success", Boolean.FALSE); String error = null;// www .jav a2 s . c o m try { // The factory instance is re-useable and thread safe. Twitter twitter = new TwitterFactory().getInstance(); Query query = new Query(term); if (latestId != null) { Long longVal = Long.valueOf(latestId); query.setSinceId(longVal); } QueryResult result = twitter.search(query); JSONArray tweets = new JSONArray(); for (Status tweet : result.getTweets()) { //System.out.println(tweet.getFromUser() + ":" + tweet.getText()); JSONObject t = new JSONObject(); t.put("id_str", String.valueOf(tweet.getId())); t.put("text", tweet.getText()); t.put("user_from", tweet.getUser().getScreenName()); t.put("img_url", tweet.getUser().getProfileImageURL()); JSONObject geo = new JSONObject(); if (tweet.getGeoLocation() != null) { geo.put("lat", tweet.getGeoLocation().getLatitude()); geo.put("lon", tweet.getGeoLocation().getLongitude()); } t.put("geo", geo); tweets.put(t); } json.put("tweets", tweets); if (tweets.length() > 0) { json.put("maxId", String.valueOf(result.getMaxId())); } else { json.put("maxId", String.valueOf(latestId)); } json.put("success", Boolean.TRUE); } catch (Exception e) { error = e.toString(); if (e.getCause() != null) { error += "; cause: " + e.getCause().toString(); } } if (error != null) { json.put("error", error); } return new StreamingResolution("application/json", new StringReader(json.toString())); }
From source file:nl.isaac.dotcms.twitter.pojo.CustomStatus.java
License:Creative Commons License
public CustomStatus(Status status) { this.createdAt = status.getCreatedAt(); this.id = status.getId(); this.id_str = String.valueOf(status.getId()); this.text = status.getText(); this.source = status.getSource(); this.isTruncated = status.isTruncated(); this.inReplyToStatusId = status.getInReplyToStatusId(); this.inReplyToUserId = status.getInReplyToUserId(); this.isFavorited = status.isFavorited(); this.inReplyToScreenName = status.getInReplyToScreenName(); this.geoLocation = status.getGeoLocation(); this.place = status.getPlace(); this.retweetCount = status.getRetweetCount(); this.isPossiblySensitive = status.isPossiblySensitive(); this.contributorsIDs = status.getContributors(); this.retweetedStatus = status.getRetweetedStatus(); this.userMentionEntities = status.getUserMentionEntities(); this.urlEntities = status.getURLEntities(); this.hashtagEntities = status.getHashtagEntities(); this.mediaEntities = status.getMediaEntities(); this.currentUserRetweetId = status.getCurrentUserRetweetId(); this.isRetweet = status.isRetweet(); this.isRetweetedByMe = status.isRetweetedByMe(); this.rateLimitStatus = status.getRateLimitStatus(); this.accessLevel = status.getAccessLevel(); this.user = status.getUser(); }
From source file:nlptexthatespeechdetection.NLPTextHateSpeechDetection.java
/** * @param args the command line arguments *//*from ww w. j a v a 2s. c o m*/ public static void main(String[] args) throws TwitterException, NotDirectoryException, IOException { HateSpeechClassifier1 classifier = new HateSpeechClassifier1(); AnnotatedDataFolder data = new AnnotatedDataFolder("data"); boolean overSampling = false; classifier.train(data.getDateSortedLabeledData(overSampling)); TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); StatusListener listener = new StatusListener() { int numHateSpeech = 0; int numTweets = 0; @Override public void onStatus(Status status) { if (status.getLang().equals("in")) { numTweets++; if (classifier.isHateSpeech(status.getText(), 0.5)) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText() + " * " + status.getId() + " # " + status.getLang() + " $ " + (status.getGeoLocation() == null ? "NULLGEO" : status.getGeoLocation().toString())); System.out.println(); System.out.println("lang: " + status.getLang()); System.out.println("number of detected hate speech: " + numHateSpeech); System.out.println("total number of streamed tweets: " + numTweets); System.out.println(); System.out.println(); numHateSpeech++; } } else { System.out.println("ignoring non-Indonesian tweet"); } // if (status.getGeoLocation() != null) { // System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText() + " * " + status.getId() + " $ " + status.getGeoLocation().toString()); // } // if (status.getLang().equals("id")) { // System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText() + " * " + status.getId() + " # " + status.getLang() + " $ " + (status.getGeoLocation() == null ? "NULLGEO" : status.getGeoLocation().toString())); // } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { // System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }; twitterStream.addListener(listener); FilterQuery filterQuery = new FilterQuery(); filterQuery.track(new String[] { "a", "i", "u", "e", "o" }); filterQuery.language("in"); twitterStream.filter(filterQuery); twitterStream.sample(); }
From source file:nyu.twitter.lg.FentchTwitter.java
License:Open Source License
public static void invoke() throws Exception { init();/*from w w w.j av a 2 s . c o m*/ // Create table if it does not exist yet if (Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is already ACTIVE"); } else { // Create a table with a primary hash key named 'name', which holds // a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("id").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("id") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest) .getTableDescription(); System.out.println("Created Table: " + createdTableDescription); // Wait for it to become active System.out.println("Waiting for " + tableName + " to become ACTIVE..."); Tables.waitForTableToBecomeActive(dynamoDB, tableName); } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("Emwo2pG").setOAuthConsumerSecret("RM9B7fske5T") .setOAuthAccessToken("19ubQOirq").setOAuthAccessTokenSecret("Lbg3C"); final TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { if (status.getGeoLocation() != null && status.getPlace() != null) { // if (count == 0) { // count++; // } // latitude = status.getGeoLocation().getLatitude(); longtitude = status.getGeoLocation().getLongitude(); place = status.getPlace().getCountry() + "," + status.getPlace().getFullName(); date = status.getCreatedAt().toString(); id = Integer.toString(count); name = status.getUser().getScreenName(); message = status.getText(); System.out.println("---------------------------"); System.out.println("ID:" + count); System.out.println("latitude:" + latitude); System.out.println("longtitude:" + longtitude); System.out.println("place:" + place); System.out.println("name:" + name); System.out.println("message:" + message); System.out.println("data:" + date); System.out.println("-------------8-------------"); insertDB(id, count, name, longtitude, latitude, place, message, date); if (++count > 100) { twitterStream.shutdown(); System.out.println("Information Collection Completed"); } // count = (count+1) % 101; } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { // System.out.println("Got a status deletion notice id:" // + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { // System.out.println("Got track limitation notice:" // + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { // System.out.println("Got scrub_geo event userId:" + userId // + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { // System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }; twitterStream.addListener(listener); twitterStream.sample(); }
From source file:nz.co.lolnet.james137137.lolnettwitchaddonbc.TwitterAPI.java
public List<Status> getLatestStatus() { List<Status> twitchTweets = new ArrayList<>(); try {/* w w w . j a v a 2s . co m*/ Query query = new Query("lolnetNZ twitch.tv"); QueryResult result; result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { if (tweet.getUser().getId() == 495479479 && tweet.getSource().contains("http://www.twitch.tv")) { twitchTweets.add(tweet); } } } catch (TwitterException te) { System.out.println("Failed to search tweets: " + te.getMessage()); } return twitchTweets; }
From source file:nz.net.speakman.android.dreamintweets.twitterstream.TwitterStreamAdapter.java
License:Apache License
private Spanned getTweetAuthor(Status tweet) { User user = tweet.getUser(); return Html.fromHtml(getClickableUrl(getUserUrl(user), user.getName())); }