List of usage examples for twitter4j StatusDeletionNotice getStatusId
long getStatusId();
From source file:birdseye.Sample.java
License:Apache License
public List<TweetData> execute(String[] args) throws TwitterException { final List<TweetData> statuses = new ArrayList(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthAccessToken("14538839-3MX2UoCEUaA6u95iWoYweTKRbhBjqEVuK1SPbCjDV"); cb.setOAuthAccessTokenSecret("nox7eYyOJpyiDiISHRDou90bGkHKasuw1IMqqJUZMaAbj"); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { public void onStatus(Status status) { String user = status.getUser().getScreenName(); String content = status.getText(); TweetData newTweet = new TweetData(user, content); statuses.add(newTweet);/*from w w w. j av a2 s. com*/ System.out.println(statuses.size() + ":" + status.getText()); if (statuses.size() > 15) { synchronized (lock) { lock.notify(); } System.out.println("unlocked"); } } public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } public void onException(Exception ex) { ex.printStackTrace(); } @Override public void onStallWarning(StallWarning sw) { System.out.println(sw.getMessage()); } }; FilterQuery fq = new FilterQuery(); String[] keywords = args; fq.track(keywords); twitterStream.addListener(listener); twitterStream.filter(fq); try { synchronized (lock) { lock.wait(); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("returning statuses"); twitterStream.shutdown(); return statuses; }
From source file:CollectionOfMentions.ControllerCollectionOfMentions.java
License:Open Source License
public void run() { startDateTime = new DateTime(); //checks on dates to make sure it's not abobe 7 days if (numberOfMinutes < 0) { numberOfMinutes = 0;/* w ww .ja v a 2 s. c om*/ } if (numberOfMinutes > 59) { numberOfMinutes = 59; } if (numberOfHours > 24) { numberOfHours = 24; } if (numberOfHours < 0) { numberOfHours = 0; } if (numberOfDays > 7) { numberOfDays = 7; } if (numberOfDays < 0) { numberOfDays = 0; } stopTime = startDateTime.getMillis() + numberOfMinutes * 60000 + numberOfHours * 3600000 + numberOfDays * 3600000 * 24; if (stopTime - startDateTime.getMillis() > 3600000 * 24 * 7) { stopTime = startDateTime.getMillis() + 3600000 * 24 * 7; } //registers actual start time in the status field opsJobInfo = dsJobsInfo.createUpdateOperations(JobInfo.class).set("status", String.valueOf(startDateTime.getMillis())); dsJobsInfo.update(updateQueryJobInfo, opsJobInfo, false, WriteConcern.UNACKNOWLEDGED); //registers actual end time in the end field opsJobInfo = dsJobsInfo.createUpdateOperations(JobInfo.class).set("end", String.valueOf(stopTime)); dsJobsInfo.update(updateQueryJobInfo, opsJobInfo, false, WriteConcern.UNACKNOWLEDGED); final Object lock = new Object(); StatusListener listener; listener = new StatusListener() { @Override public void onStatus(Status status) { nbTweets++; if (System.currentTimeMillis() > stopTime) { //updating the job a last time; //************************************** //saving statuses to the db. // if (!twitterStatuses.isEmpty()) { // opsJob = dsJobs.createUpdateOperations(Job.class).addAll("statuses", statusesIds, true); // dsJobs.update(updateQueryJob, opsJob); // // dsTweets.save(twitterStatuses); // } // 91 is the code for twitter stream has stopped collecting. progress = 91; //recording the progress, nbTweets and end time of the job opsJobInfo = dsJobsInfo.createUpdateOperations(JobInfo.class).set("progress", progress) .set("nbTweets", nbTweets).set("end", System.currentTimeMillis()); dsJobsInfo.update(updateQueryJobInfo, opsJobInfo); synchronized (lock) { lock.notify(); } } else { tweet = new Tweet(); tweet.setStatus(TwitterObjectFactory.getRawJSON(status)); tweet.setIdTweet(nbTweets); tweet.setJobId(jobUUID); //// System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); // twitterStatus = convertStatus.convertOneToTwitterStatus(status); // twitterStatus.setJobId(jobUUID); // twitterStatuses.add(twitterStatus); // // // // statusesIds.add(status.getId()); // timeSinceLastStatus = System.currentTimeMillis() - timeLastStatus; // // //************************************** // //adjusting the frequency of saves to DB, function of number of statuses received per second // if (timeSinceLastStatus < 200) { // sizeBatch = 100; // } else { // sizeBatch = 25; // } // timeLastStatus = System.currentTimeMillis(); // progressLong = (Long) ((System.currentTimeMillis() - startDateTime.getMillis()) * 98 / (stopTime - startDateTime.getMillis())); // if (statusesIds.size() > sizeBatch || progressLong.intValue() > progress) { //************************************** //saving statuses to the db. try { dsTweets.save(tweet, WriteConcern.UNACKNOWLEDGED); opsJobInfo = dsJobsInfo.createUpdateOperations(JobInfo.class).set("nbTweets", nbTweets); dsJobsInfo.update(updateQueryJobInfo, opsJobInfo, false, WriteConcern.UNACKNOWLEDGED); } catch (MongoException m) { System.out.println("saving of statuses to the db failed"); } // twitterStatuses = new ArrayList(); // // //************************************** // //updating list of status ids of the job. // opsJob = dsJobs.createUpdateOperations(Job.class).addAll("statuses", statusesIds, true); // dsJobs.update(updateQueryJob, opsJob); // statusesIds = new ArrayList(); // // //updating progress. // System.out.println("progress: " + progressLong); // progress = progressLong.intValue(); // opsJobInfo = dsJobsInfo.createUpdateOperations(JobInfo.class).set("progress", progress).set("nbTweets", nbTweets); // dsJobsInfo.update(updateQueryJobInfo, opsJobInfo); //************************************** // } } } @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 onException(Exception ex) { System.out.println("Exception: " + ex); } @Override public void onStallWarning(StallWarning sw) { System.out.println("Got stall warning:" + sw.getMessage()); } }; twitterStream.addListener(listener); FilterQuery fq = new FilterQuery(); String[] mentions = mention.split(","); fq.track(mentions); // twitterStream.filter(new FilterQuery(0, users, keywords)); twitterStream.filter(fq); try { synchronized (lock) { lock.wait(); } } catch (InterruptedException e) { } try { twitterStream.shutdown(); } catch (Exception e) { System.out.println("exception when shutdown of twitter stream"); System.out.println("error: " + e.getMessage()); } System.out.println("shutdown of twitter stream was successful"); }
From source file:com.babatunde.twittergoogle.Utility.java
public void postToGoogle(PlusDomains s, String id, String hashtag) { try {/* w w w . j av a 2 s .c o m*/ final PlusDomains serve = s; final String circleID = id; listener = new StatusListener() { @Override public void onStatus(Status status) { String msg = status.getUser().getName() + " - " + "@" + status.getUser().getScreenName() + " - " + status.getText(); System.out.println(msg); //Create a list of ACL entries if (serve != null && (!circleID.isEmpty() || (circleID != null))) { PlusDomainsAclentryResource resource = new PlusDomainsAclentryResource(); resource.setType("domain").setType("circle").setId(circleID); //Get Emails of people in the circle. List<PlusDomainsAclentryResource> aclEntries = new ArrayList<PlusDomainsAclentryResource>(); aclEntries.add(resource); Acl acl = new Acl(); acl.setItems(aclEntries); acl.setDomainRestricted(true); // Required, this does the domain restriction // Create a new activity object Activity activity = new Activity() .setObject(new Activity.PlusDomainsObject().setOriginalContent(msg)).setAccess(acl); try { // Execute the API request, which calls `activities.insert` for the logged in user activity = serve.activities().insert("me", activity).execute(); } catch (IOException ex) { Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); } } } @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(); } }; } catch (Exception e) { } TwitterStream twitterStream = new TwitterStreamFactory(configuration).getInstance(); twitterStream.addListener(listener); String str[] = { hashtag }; twitterStream.shutdown(); try { Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); } twitterStream.filter(new FilterQuery().track(str)); }
From source file:com.freshdigitable.udonroad.util.TwitterResponseMock.java
License:Apache License
@NonNull public static StatusDeletionNotice createDeletionNotice(final Status target) { final StatusDeletionNotice mock = mock(StatusDeletionNotice.class); final long statusId = target.getId(); when(mock.getStatusId()).thenReturn(statusId); final long userId = target.getUser().getId(); when(mock.getUserId()).thenReturn(userId); return mock;//from w ww. j a v a 2s. co m }
From source file:com.github.jcustenborder.kafka.connect.twitter.StatusConverter.java
License:Apache License
public static void convert(StatusDeletionNotice statusDeletionNotice, Struct struct) { struct.put("StatusId", statusDeletionNotice.getStatusId()); struct.put("UserId", statusDeletionNotice.getUserId()); }
From source file:com.github.jcustenborder.kafka.connect.twitter.StatusConverter.java
License:Apache License
public static void convertKey(StatusDeletionNotice statusDeletionNotice, Struct struct) { struct.put("StatusId", statusDeletionNotice.getStatusId()); }
From source file:com.isdp.twitterposter.TwitterManager.java
License:Open Source License
public void startTwitterStream() { TwitterStream twitterStream = new TwitterStreamFactory(configuration).getInstance(); StatusListener listener = new StatusListener() { @Override//from www. jav a 2 s . com public void onStatus(Status status) { try { System.out.println("Text recieved: @" + status.getUser().getScreenName() + " - " + status.getText() + "\n"); StringTokenizer st = new StringTokenizer(status.getText(), " "); //first token indicates search engine String searchEngine = st.nextToken(); //burn the next random token String randToken = st.nextToken(); //next token indicates max number of results to return int maxResults = Integer.parseInt(st.nextToken()); String searchString = ""; while (st.hasMoreTokens()) { searchString += st.nextToken() + " "; } if (searchEngine.equals(GoogleManager.TAG_YELP)) { String[] results = GoogleManager.getInstance().trySearch(searchString, GoogleManager.SEARCH_YELP); if (results != null) { for (int i = 0; i < results.length && i < maxResults; ++i) { String tweetMsg = Util.truncateString(results[i], TWITTER_CHARACTER_LIMIT); System.out.println("Tweeting" + tweetMsg); tweet(tweetMsg); } } else if (results == null || results.length == 0) { tweet(Util.generateRandomString(7) + "\n" + "No results found!"); } } else if (searchEngine.equals(GoogleManager.TAG_WIKI)) { String[] results = GoogleManager.getInstance().trySearch(searchString, GoogleManager.SEARCH_WIKI); if (results != null) { for (int i = 0; i < results.length && i < maxResults; ++i) { String tweetMsg = Util.generateRandomString(3) + "\n" + Util.shortenText(results[i]); tweetMsg = Util.truncateString(tweetMsg, TWITTER_CHARACTER_LIMIT); System.out.println("Tweeting " + tweetMsg); tweet(tweetMsg); } } else if (results == null || results.length == 0) { tweet(Util.generateRandomString(7) + "\n" + "No results found!"); } } } catch (Exception e) { } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println( "onDeletionNotice: Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out .println("onTrackLimitationNotice: Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println( "onScrubGeo: Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("onStallWarning: Got stall warning:" + warning); } @Override public void onException(Exception ex) { System.out.println("onException" + ex.toString()); } }; twitterStream.addListener(listener); FilterQuery tweetFilterQuery = new FilterQuery(); tweetFilterQuery.follow(new long[] { FOLLOW_ID }); twitterStream.filter(tweetFilterQuery); }
From source file:com.isdp.twitterposterandroid.TwitterManager.java
License:Open Source License
public void startTwitterStream() { TwitterStream twitterStream = new TwitterStreamFactory(configuration).getInstance(); StatusListener listener = new StatusListener() { @Override/*from ww w . j av a 2s. c o m*/ public void onStatus(Status status) { try { Log.d("Text recieved", "@" + status.getUser().getScreenName() + " - " + status.getText() + "\n"); StringTokenizer st = new StringTokenizer(status.getText(), " "); //first token indicates search engine String searchEngine = st.nextToken(); //burn the next random token String randToken = st.nextToken(); //next token indicates max number of results to return int maxResults = Integer.parseInt(st.nextToken()); String searchString = ""; while (st.hasMoreTokens()) { searchString += st.nextToken() + " "; } if (searchEngine.equals(GoogleManager.TAG_YELP)) { String[] results = GoogleManager.getInstance().trySearch(searchString, GoogleManager.SEARCH_YELP); if (results != null) { for (int i = 0; i < results.length && i < maxResults; ++i) { String tweetMsg = Util.truncateString(results[i], TWITTER_CHARACTER_LIMIT); Log.d("Tweeting", tweetMsg); tweet(tweetMsg); } } else if (results == null || results.length == 0) { tweet(Util.generateRandomString(7) + "\n" + "No results found!"); } } else if (searchEngine.equals(GoogleManager.TAG_WIKI)) { String[] results = GoogleManager.getInstance().trySearch(searchString, GoogleManager.SEARCH_WIKI); if (results != null) { for (int i = 0; i < results.length && i < maxResults; ++i) { String tweetMsg = Util.generateRandomString(3) + "\n" + Util.shortenText(results[i]); tweetMsg = Util.truncateString(tweetMsg, TWITTER_CHARACTER_LIMIT); Log.d("Tweeting", tweetMsg); tweet(tweetMsg); } } else if (results == null || results.length == 0) { tweet(Util.generateRandomString(7) + "\n" + "No results found!"); } } } catch (Exception e) { } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { Log.d("onDeletionNotice", "Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { Log.d("onTrackLimitationNotice", "Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { Log.d("onScrubGeo", "Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { Log.d("onStallWarning", "Got stall warning:" + warning); } @Override public void onException(Exception ex) { Log.d("onException", ex.toString()); } }; twitterStream.addListener(listener); FilterQuery tweetFilterQuery = new FilterQuery(); tweetFilterQuery.follow(new long[] { FOLLOW_ID }); twitterStream.filter(tweetFilterQuery); }
From source file:com.left8.evs.utilities.dsretriever.TweetsRetriever.java
License:Open Source License
/** * Method that handles the Twitter streaming API. <br> * <b>WARNING:</b> Method does not terminate by itself, due to the fact that * the streamer runs in a different thread. * @param keywords The keywords for which the streamer searches for tweets. * @param mongoDB A handler for the MongoDB database. * @param config A configuration object. *//*w w w . j ava 2 s . c o m*/ public final void retrieveTweetsWithStreamingAPI(String[] keywords, MongoHandler mongoDB, Config config) { ConfigurationBuilder cb = getAuthorization(); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); final StatusListener listener; listener = new StatusListener() { @Override public final void onStatus(Status status) { //Insert tweet to MongoDB mongoDB.insertSingleTweetIntoMongoDB(status, "NULL"); } @Override public final void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { Utilities.printMessageln("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public final void onTrackLimitationNotice(int numberOfLimitedStatuses) { Utilities.printMessageln("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public final void onScrubGeo(long userId, long upToStatusId) { Utilities.printMessageln("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public final void onStallWarning(StallWarning warning) { Utilities.printMessageln("Got stall warning:" + warning); } @Override public final void onException(Exception ex) { ex.printStackTrace(System.out); } }; FilterQuery fq = new FilterQuery(); fq.language("en"); //Set language of tweets to "English" fq.track(keywords); //Load the search terms twitterStream.addListener(listener); //Start listening to the stream twitterStream.filter(fq); //Apply the search filters }
From source file:com.mycompany.twittersearch.StatusListener.java
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); }