List of usage examples for twitter4j Status getUserMentionEntities
UserMentionEntity[] getUserMentionEntities();
From source file:de.vanita5.twittnuker.model.ParcelableUserMention.java
License:Open Source License
public static ParcelableUserMention[] fromStatus(final Status status) { return fromUserMentionEntities(status.getUserMentionEntities()); }
From source file:de.vanita5.twittnuker.util.TwitterContentUtils.java
License:Open Source License
@NonNull public static String getInReplyToName(@NonNull final Status status) { final Status orig = status.isRetweet() ? status.getRetweetedStatus() : status; final long inReplyToUserId = status.getInReplyToUserId(); final UserMentionEntity[] entities = status.getUserMentionEntities(); if (entities == null) return orig.getInReplyToScreenName(); for (final UserMentionEntity entity : entities) { if (inReplyToUserId == entity.getId()) return entity.getName(); }/*from w w w. ja va2s . c o m*/ return orig.getInReplyToScreenName(); }
From source file:gh.polyu.user.TrackUsers.java
License:Apache License
public void track(final int no, final int p) { final TwitterDBHandle handle = new TwitterDBHandle(); handle.intialTwitterDBhandle();/*from w w w. j a va 2s . com*/ while (alive) { alive = false; StatusListener listener = new StatusListener() { ArrayList<_TweetLink> listlink = new ArrayList<_TweetLink>(); int cnt = 0; String oldmonth = "20138"; String table = "UserTweet20138"; String oldday = ""; String currentday = ""; String currentmonth = ""; long lastinsert = 0l; long nowinsert = 0l; int newday = 0; String newtime = ""; @Override public void onStatus(Status status) { if (status.getId() == 123 && status.getText().equals("YOU are WORNG!.")) { System.out.println("Connection Need to be rebuilt!!"); alive = true; } else if (status.getLang().equals("en")) { _TweetLink tweet = new _TweetLink(); String Test = status.getText(); tweet.setText(Test); Date time = status.getCreatedAt(); tweet.setTime(time); tweet.setUserName(status.getUser().getName()); HashtagEntity[] hashtagentity = status.getHashtagEntities(); StringBuffer hashen = new StringBuffer(); for (int i = 0; i < hashtagentity.length; i++) { hashen.append(hashtagentity[i].getText()); hashen.append(";"); } tweet.setHashtag(hashen.toString()); URLEntity[] URLEn = status.getURLEntities(); StringBuffer URL = new StringBuffer(); for (int i = 0; i < URLEn.length; i++) { URL.append(URLEn[i].getURL()); URL.append(";"); } tweet.setURL(URL.toString()); //user mention UserMentionEntity[] userEn = status.getUserMentionEntities(); StringBuffer mentuser = new StringBuffer(); for (int i = 0; i < userEn.length; i++) { mentuser.append(userEn[i].getId()); mentuser.append(";"); } tweet.setUerMention(mentuser.toString()); //if(mentuser.length()!=0); //System.out.println("mentuser: "+ mentuser); //tweetID tweet.setTweetID(status.getId()); //if(ID!=null) // original twitterID tweet.setOriginID(status.getInReplyToStatusId()); //original user ID tweet.setOriginUser(status.getInReplyToUserId()); // user ID User users = status.getUser(); tweet.setTweetUser(users.getId()); //places Place Pl = status.getPlace(); String place = ""; if (Pl != null) { place = Pl.getFullName(); //System.out.println("place "+place); } tweet.setPlace(place); // Retweetcoun long num = 0; if (status.getRetweetedStatus() != null) { num = status.getRetweetedStatus().getRetweetCount(); //System.out.println("retweetcount"+num); tweet.setRetweetCount(num); tweet.setRetweet(1); } else { tweet.setRetweetCount(0); tweet.setRetweet(0); } // if(Retweet!=null) //System.out.println("Retweetcount: "+ Retweet); //isfavourate boolean favourate = status.isFavorited(); /*if(favourate) { fav = 1; tweet.setFavourate(fav); fav =0; System.out.println("isf "+ fav); }*/ // is retweet //String other = status.toString(); // tweet.setOther(other); listlink.add(tweet); Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); currentmonth = String.valueOf(year) + String.valueOf(month); currentday = String.valueOf(day); if (currentmonth.equals(oldmonth)) { if (currentday.equals(oldday)) ; else { newday = 1; SimpleDateFormat formatter = new SimpleDateFormat("MMddHH:mm:ss "); Date curDate = new Date(System.currentTimeMillis());// newtime = formatter.format(curDate); } } else { try { handle.database_connection(); table = "UserTweet" + String.valueOf(year) + String.valueOf(month); System.out.println("create new table " + table); String CREATE_TABLE = "create table " + table + "(TweetID varchar(100), UserName varchar(200), TwitterUser varchar(145), OriginID varchar(100), OriginUser varchar(100), place varchar(100), RetweetCount varchar(100), isRetweet int(5), Text varchar(500), Time datetime," + "Hashtag varchar(200), URL varchar(200), UerMention varchar(200))"; Statement st = handle.conn.createStatement(); st.execute(CREATE_TABLE); String Create_Index = "alter table " + table + " add index time (Time)"; st.execute(Create_Index); String Create_Index2 = "alter table " + table + " add index userID (TwitterUser)"; st.execute(Create_Index2); String key = "ALTER TABLE " + table + " ADD PRIMARY KEY (TweetID)"; st.execute(key); } catch (SQLException e) { e.printStackTrace(); } handle.close_databasehandle(); try { TwitterDBHandle handle2 = new TwitterDBHandle(); handle2.intialTwitterDBhandle2(); handle2.database_connection(); table = "UserTweet" + String.valueOf(year) + String.valueOf(month); System.out.println("create new table " + table); String CREATE_TABLE = "create table " + table + "(TweetID varchar(100), UserName varchar(200), TwitterUser varchar(145), OriginID varchar(100), OriginUser varchar(100), place varchar(100), RetweetCount varchar(100), isRetweet int(5), Text varchar(500), Time datetime," + "Hashtag varchar(200), URL varchar(200), UerMention varchar(200))"; Statement st = handle2.conn.createStatement(); st.execute(CREATE_TABLE); String Create_Index = "alter table " + table + " add index time (Time)"; st.execute(Create_Index); String Create_Index2 = "alter table " + table + " add index userID (TwitterUser)"; st.execute(Create_Index2); String key = "ALTER TABLE " + table + " ADD PRIMARY KEY (TweetID)"; st.execute(key); handle2.close_databasehandle(); } catch (SQLException e) { e.printStackTrace(); } } //System.out.println("OTHER: "+ other); if ((cnt++) % 1000 == 0) { if (newday == 1) { newday = 0; oldday = currentday; GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy"); gs.send("THREAD" + p + " :" + "program no" + no + "message" + newtime, "I am still alive"); newtime = ""; } try { handle.database_connection(); handle.userTweet(table, listlink); nowinsert = System.currentTimeMillis(); System.err.println( "No: " + no + "program " + "totally " + cnt + " tweets downloaded!\n" + new Date(nowinsert) + " " + new Date(lastinsert)); lastinsert = nowinsert; nowinsert = 0l; handle.close_databasehandle(); } catch (SQLException e) { handle.close_databasehandle(); e.printStackTrace(); // TODO Auto-generated catch block TwitterDBHandle handle2 = new TwitterDBHandle(); handle2.intialTwitterDBhandle2(); handle2.database_connection(); try { handle2.userTweet(table, listlink); nowinsert = System.currentTimeMillis(); System.err.println("New Database No: " + no + "program " + "totally " + cnt + " tweets downloaded!\n" + new Date(nowinsert) + new Date(lastinsert)); lastinsert = nowinsert; nowinsert = 0l; handle2.close_databasehandle(); } catch (SQLException e1) { // TODO Auto-generated catch block GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy"); try { gs.SendSSLMessage("cscchenyoyo@gmail.com", "program error", "both databases are down"); } catch (MessagingException ee) { // TODO Auto-generated catch block e.printStackTrace(); } } GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy"); try { gs.SendSSLMessage("cscchenyoyo@gmail.com", "program error", "change database to another one"); } catch (MessagingException ee) { // TODO Auto-generated catch block e.printStackTrace(); } } listlink.clear(); } } } @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 twitterStream = new TwitterStreamFactory().getInstance(); twitterOAuth twtOauth = new twitterOAuth(); twtOauth.AuthoritywithS(twitterStream, key); twitterStream.addListener(listener); twitterStream.filter(new FilterQuery(0, follow)); /* try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ } }
From source file:Group5.Model.java
public static void Tweet(String inputTweet) throws TwitterException { //Your Twitter App's Consumer Key String consumerKey = "wK7lQLpl3t8xvIABqpgoJzYYd"; //Your Twitter App's Consumer Secret String consumerSecret = "4M5TgmNfS0EKeaSqna8eHTNaNi970Plq3dynX5gvYsh848j0mj"; //Your Twitter Access Token String accessToken = "829891753473892361-7jkKyXLYc6HOStzCPGjWOnVoAVNU7cd"; //Your Twitter Access Token Secret String accessTokenSecret = "ATidrzRzhVqAamuMbYiskcHBPSisB9MWsCsYYY2Bec4y9"; //Instantiate a re-usable and thread-safe factory TwitterFactory twitterFactory = new TwitterFactory(); //Instantiate a new Twitter instance Twitter twitter = twitterFactory.getInstance(); //setup OAuth Consumer Credentials twitter.setOAuthConsumer(consumerKey, consumerSecret); //setup OAuth Access Token twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); //Instantiate and initialize a new twitter status update StatusUpdate statusUpdate = new StatusUpdate( //your tweet or status message inputTweet);/*from w w w . j av a 2s. co m*/ //tweet or update status Status status = twitter.updateStatus(statusUpdate); //response from twitter server System.out.println("status.toString() = " + status.toString()); System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName()); System.out.println("status.getSource() = " + status.getSource()); System.out.println("status.getText() = " + status.getText()); System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities())); System.out.println("status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities())); }
From source file:io.rakam.datasource.twitter.TweetProcessor.java
License:Apache License
@Override public void onStatus(Status status) { Map<String, Object> map = new HashMap<>(); GeoLocation geoLocation = status.getGeoLocation(); if (geoLocation != null) { map.put("latitude", geoLocation.getLatitude()); map.put("longitude", geoLocation.getLongitude()); }/* w w w. j a v a2 s. c o m*/ map.put("_time", status.getCreatedAt().getTime()); Place place = status.getPlace(); if (place != null) { map.put("country_code", place.getCountryCode()); map.put("place", place.getName()); map.put("place_type", place.getPlaceType()); map.put("place_id", place.getId()); } User user = status.getUser(); map.put("_user", user.getId()); map.put("user_lang", user.getLang()); map.put("user_created", user.getCreatedAt()); map.put("user_followers", user.getFollowersCount()); map.put("user_status_count", user.getStatusesCount()); map.put("user_verified", user.isVerified()); map.put("id", status.getId()); map.put("is_reply", status.getInReplyToUserId() > -1); map.put("is_retweet", status.isRetweet()); map.put("has_media", status.getMediaEntities().length > 0); map.put("urls", Arrays.stream(status.getURLEntities()).map(URLEntity::getText).collect(Collectors.toList())); map.put("hashtags", Arrays.stream(status.getHashtagEntities()).map(HashtagEntity::getText) .collect(Collectors.toList())); map.put("user_mentions", Arrays.stream(status.getUserMentionEntities()).map(UserMentionEntity::getText) .collect(Collectors.toList())); map.put("language", "und".equals(status.getLang()) ? null : status.getLang()); map.put("is_positive", classifier.isPositive(status.getText())); Event event = new Event().properties(map).collection(collection); buffer.add(event); commitIfNecessary(); }
From source file:it.unipr.aotlab.TwitterMiner.twitter.client.TwitterStreamListener.java
License:Open Source License
/** * This method calls the update function of the database to store * informations about received tweets//ww w .j a v a 2s . c o m */ @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); hashtag = status.getHashtagEntities(); mentions = status.getUserMentionEntities(); redisDB.update(status.getUser().getScreenName(), hashtag, mentions); }
From source file:jp.wda.azeda.core.daemons.impl.RetweetsCrawlerImpl.java
License:Apache License
/** * *///from w w w . j a v a2 s . co m @Aspect("aop.requiredTx") public void crawl() throws TwitterException { log.debug("crawl retweets!!" + tweets.size()); if (tweets.size() == 0) { loadTweets(); } if (tweets.size() == 0) { return; } RetweetedTweet tweet = tweets.remove(0); log.debug("check tweet " + tweet.getTweetID()); Twitter twitter = new TwitterFactory().getInstance(); AccessToken accessToken = new AccessToken(tweet.getAccessToken().getAccessToken(), tweet.getAccessToken().getAccessTokenSecret()); twitter.setOAuthAccessToken(accessToken); ResponseList<Status> rt = getRetweets(twitter, tweet.getTweetID()); if (!alive) { return; } if (rt == null || rt.size() == 0) { return; } HashMap<Long, Status> retweets = new HashMap<Long, Status>(); for (Status status : rt) { retweets.put(status.getUser().getId(), status); } List<Retweeter> registered = retweetersDao.getRetweeterIDs(tweet.getTweetID()); for (Retweeter retweeter : registered) { long registeredUserID = retweeter.getRetweeterID(); if (retweets.containsKey(registeredUserID)) { retweets.remove(registeredUserID); continue; } } if (retweets.size() == 0) { return; } for (Status status : retweets.values()) { long retweeter = status.getUser().getId(); long oldest = System.currentTimeMillis() - retweetExpired * 60 * 1000L; if (status.getCreatedAt().getTime() < oldest) { log.info(tweet.getTweetID() + " retweet by " + status.getUser().getScreenName() + " ? " + retweetExpired + "?????????"); insertRetweeter(twitter.getId(), tweet.getTweetID(), retweeter); continue; } List<Status> userTimeline = loadRetweetersTweets(twitter, tweet.getTweetID(), retweeter, 1); if (!alive) { return; } if (userTimeline == null) { continue; } int skips = 0; for (int i = userTimeline.size() - 1; i >= 0; i--) { Status s = userTimeline.get(i); UserMentionEntity[] mentions = s.getUserMentionEntities(); if (s.isRetweet()) { skips++; continue; } if (mentions == null || mentions.length > 0) { skips++; continue; } log.debug(s.getId() + ":" + s.getCreatedAt() + "(" + s.isRetweet() + ") " + s.getText()); Retweet retweet = new Retweet(); retweet.setTweetID(s.getId()); retweet.setRetweetTo(tweet.getTweetID()); retweet.setRetweeterID(retweeter); retweet.setTweettext(s.getText()); retweet.setCreatedat(new Timestamp(s.getCreatedAt().getTime())); retweet.setSkiptweets(skips); retweet.setScreenName(status.getUser().getScreenName()); dtoRetweets.add(retweet); insertRetweeter(twitter.getId(), tweet.getTweetID(), retweeter); break; } } register(); }
From source file:Logic.mongoC.java
public void IngresarUsuario(String name) { String[] buscarUs = new String[1]; buscarUs[0] = name;/*from w w w .ja v a 2 s . c o m*/ try { ResponseList<twitter4j.User> use = twitter.lookupUsers(buscarUs); twitter4j.User u = use.get(0); System.out.println(u.getStatus()); usuario nuevoS = new usuario(); nuevoS.setId(Long.toString(u.getId())); nuevoS.setNombre(u.getName()); nuevoS.setLocation(u.getLocation()); nuevoS.setNumFol(u.getFollowersCount()); nuevoS.setNumeroDeT(u.getStatusesCount()); List<Status> twitts = twitter.getUserTimeline(u.getId(), new Paging(1, 200)); ArrayList<twitt> timeL = new ArrayList(); for (Status s : twitts) { twitt tw = new twitt(); tw.setTexto(s.getText()); tw.setRetwett(s.getRetweetCount()); //tw.setFecha((java.util.Date) s.getCreatedAt()); tw.setFav(s.getFavoriteCount()); tw.setCreador(s.getUser().getScreenName()); UserMentionEntity[] userMentionEntities = s.getUserMentionEntities(); ArrayList<String> inter = new ArrayList(); for (UserMentionEntity uh : userMentionEntities) { inter.add(uh.getScreenName()); } tw.setPersonas(inter); timeL.add(tw); } nuevoS.setTimeline(timeL); final String fIns = gson.toJson(nuevoS); Document dt; dt = new Document("ScreenName", u.getScreenName()); dt.append("todo", fIns); conect(); coll.insertOne(dt); JOptionPane.showMessageDialog(null, "Usuario Ingresado"); } catch (TwitterException ex) { System.out.println("No se pudo conectar el usuario deseado"); } }
From source file:net.lacolaco.smileessence.twitter.util.TwitterUtils.java
License:Open Source License
/** * Get array of screenName in own text// ww w. ja va 2 s. c o m * * @param status status * @param excludeScreenName * @return */ public static Collection<String> getScreenNames(Status status, String excludeScreenName) { ArrayList<String> names = new ArrayList<>(); names.add(status.getUser().getScreenName()); if (status.getUserMentionEntities() != null) { for (UserMentionEntity entity : status.getUserMentionEntities()) { if (names.contains(entity.getScreenName())) { continue; } names.add(entity.getScreenName()); } } if (excludeScreenName != null) { names.remove(excludeScreenName); } return names; }
From source file:net.lacolaco.smileessence.viewmodel.StatusViewModel.java
License:Open Source License
public StatusViewModel(Status status, Account account) { if (status.isRetweet()) { retweetedStatus = new StatusViewModel(status.getRetweetedStatus(), account); }//w w w . j ava 2 s . c o m id = status.getId(); text = TwitterUtils.replaceURLEntities(status.getText(), status.getURLEntities(), false); createdAt = status.getCreatedAt(); source = status.getSource(); mentions = status.getUserMentionEntities(); hashtags = status.getHashtagEntities(); media = status.getMediaEntities(); urls = status.getURLEntities(); symbols = status.getSymbolEntities(); User user = status.getUser(); UserCache.getInstance().put(user); userID = user.getId(); screenName = user.getScreenName(); name = user.getName(); iconURL = user.getProfileImageURLHttps(); isProtected = user.isProtected(); setMention(isMention(account.screenName)); setMyStatus(isMyStatus(account.userID)); setRetweetOfMe(isRetweetOfMe(account.userID)); }