List of usage examples for twitter4j Status getText
String getText();
From source file:org.opensocial.TwitterProxy.java
License:Apache License
/** * Called on HTTP GET//from w ww .ja v a 2 s .c o m * Returns last 20 tweets from the user using "screen_name". * If screenName is null or an empty string, we return the last 20 tweets from the public * timeline * @param screenName * @return JSON Response a ActivityStream Activity collection for the set tweets */ @GET @Produces(MediaType.APPLICATION_JSON) public Object getTweets(@QueryParam("screen_name") String screenName) { JSONArray resultArray = new JSONArray(); ResponseList<Status> list = null; try { if (screenName == null || screenName.equals("")) { list = twitter.getHomeTimeline(); } else { list = twitter.getUserTimeline(screenName); } System.out.println("Rate limit: " + list.getRateLimitStatus().getRemainingHits()); Iterator<Status> iter = list.iterator(); while (iter.hasNext()) { Status status = iter.next(); ActivityBuilder activityBuilder = Activity.makeActivity().id(Long.toString(status.getId())) .verb(Verb.POST).published(new DateTime(status.getCreatedAt().getTime())) .source(ASObject.makeObject(ASObject.SOURCE).displayName(status.getSource())) .author(PersonObject.makePerson(status.getUser().getScreenName()) .id(Long.toString(status.getUser().getId())) .image(MediaLink .makeMediaLink(status.getUser().getProfileImageURL().toExternalForm())) .get()); boolean eeAdded = false; eeAdded = EmbeddedExperiences.addHashtagEE(uriInfo, status, activityBuilder); if (!eeAdded) { eeAdded = EmbeddedExperiences.addUrlMatchedEE(uriInfo, status, activityBuilder); } if (!eeAdded) { eeAdded = EmbeddedExperiences.addUrlStyleEE(status, activityBuilder); } activityBuilder.content(status.getText()); Activity activity = activityBuilder.get(); StringWriter swriter = new StringWriter(); activity.writeTo(swriter); JSONObject jobj = new JSONObject(swriter.toString()); resultArray.put(jobj); } return resultArray; } catch (Exception e) { e.printStackTrace(); return Response.serverError().entity(e).build(); } }
From source file:org.osframework.maven.plugins.twitter.TweetMojo.java
License:Apache License
protected void executeInTwitter(Twitter twitter) throws MojoExecutionException, MojoFailureException { try {//from w ww .j a v a 2 s .c om Status status = twitter.updateStatus(getMessage()); getLog().info("Sent tweet: " + status.getText()); logStatus(status); } catch (TwitterException te) { throw new MojoFailureException("Could not send tweet", te); } }
From source file:org.osframework.maven.plugins.twitter.TweetMojo.java
License:Apache License
private void logStatus(Status status) { StringBuilder logMsg = new StringBuilder(formatDate(status.getCreatedAt())).append(" ") .append(status.getText()); File logFile = new File(getWorkDirectory(), "tweet.log"); BufferedWriter writer = null; try {/*from ww w . j a v a 2 s. co m*/ writer = new BufferedWriter(new FileWriter(logFile, true)); writer.write(logMsg.toString()); } catch (IOException ioe) { getLog().warn("Could not write status to tweet.log"); } finally { IOUtil.close(writer); } }
From source file:org.ow2.frascati.akka.fabric.peakforecast.lib.TwitterImpl.java
License:Open Source License
@Override public void updateStatus(String message) { try {// w w w. j a v a 2s . c o m ConfigurationBuilder cb = new ConfigurationBuilder(); //info OAuth settings de l'application twitter tweetpeakforecast enregistr par l'utilisateur @peakforecast cb.setDebugEnabled(true).setOAuthConsumerKey("0PqersXnGOn7AirB13jszw") .setOAuthConsumerSecret("r3qyCuhmwRI90JY04kqcYtn5yEl6yaW1UoRhAY08Q") .setOAuthAccessToken("1598158057-epoKcN3Lfz405zjNZQ2rl5cx74lthvBZ93cCsfj") .setOAuthAccessTokenSecret("6YwDPdjS7OpqDHb6PsmW0beOjCgjITzDGYV89gtQU"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); Status status = twitter.updateStatus(message); System.out.println("Successfully updated the status to [" + status.getText() + "]."); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.primefaces.examples.view.TwitterSearchView.java
License:Apache License
public void start() { if (!active) { PushContext context = PushContextFactory.getDefault().getPushContext(); context.schedule("/twitter", new Callable<String>() { private String results; public String call() throws Exception { List<Status> tweets = twitterService.asyncSearch("I"); if (tweets != null) { JSONObject jSONObject = new JSONObject(); JSONArray jSONArray = new JSONArray(); for (Status t : tweets) { JSONObject j = new JSONObject(); j.put("from_user", t.getUser().getScreenName()); j.put("text", t.getText()); j.put("image", t.getUser().getMiniProfileImageURL()); jSONArray.put(j); }//from w w w . j a v a 2 s . c o m jSONObject.put("results", jSONArray); results = "{\"data\":" + jSONObject.toString() + "}"; } return results; } }, 10, TimeUnit.SECONDS); active = true; } }
From source file:org.rhq.plugins.twitter.TwitterComponent.java
License:Open Source License
/** * Implementation of the OperationFacet/*from w w w . j ava2 s.c o m*/ * Sends a tweet * @param name the name of the operation * @param configuration parameters of the operation * @return result of the operation * @throws Exception If anything goes wrong */ public OperationResult invokeOperation(String name, Configuration configuration) throws Exception { if (name != null && name.equals("postStatus")) { if (username == null || password == null) { throw new IllegalArgumentException("User or password were not set"); } String message = configuration.getSimpleValue("message", null); Twitter twitter = createTwitterInstance(); Status status = twitter.updateStatus(message); @SuppressWarnings({ "UnnecessaryLocalVariable" }) OperationResult result = new OperationResult("Posted " + status.getText()); return result; } throw new UnsupportedOperationException("Operation " + name + " is not valid"); }
From source file:org.rhq.plugins.twitter.TwitterEventPoller.java
License:Open Source License
/** * Add statuses to the list of events to return * @param statuses//from w w w .j av a2 s. co m */ public void addStatuses(List<Status> statuses) { synchronized (events) { for (Status status : statuses) { Event ev = new Event(getEventType(), // Event Type status.getUser().getName(), // SourceLocation status.getCreatedAt().getTime(), // Timestamp EventSeverity.INFO, // Severity -- just all the same for now status.getText()); events.add(ev); } } }
From source file:org.richfaces.examples.tweetstream.dataserver.listeners.TweetStreamListener.java
License:Open Source License
private Tweet createTweet(Status status) { //create a new tweet from the status update Tweet tweet = new Tweet(); tweet.setText(status.getText()); tweet.setId(status.getUser().getId()); tweet.setProfileImageUrl(status.getUser().getProfileImageURL().toString()); tweet.setScreenName(status.getUser().getScreenName()); if (status.getRetweetedStatus() != null) { tweet.setRetweet(status.getRetweetedStatus().isRetweet()); }//from w ww . j a v a 2s. co m //process hashtags in the tweet HashtagEntity[] hashtagEntities = status.getHashtagEntities(); if (hashtagEntities != null) { ArrayList<String> curTags = new ArrayList<String>(hashtagEntities.length); for (HashtagEntity tw4jTag : hashtagEntities) { curTags.add(tw4jTag.getText()); } tweet.setHashTags(curTags.toArray(new String[0])); } else { tweet.setHashTags(new String[0]); } return tweet; }
From source file:org.rtsa.storm.TwitterSpout.java
License:Apache License
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<Status>(1000); _collector = collector;//from w w w. ja va 2 s . c om StatusListener listener = new StatusListener() { public void onStatus(Status status) { if (status.getText().length() != 0 && status.getLang().equals("en")) { queue.offer(status); } } public void onDeletionNotice(StatusDeletionNotice sdn) { } public void onTrackLimitationNotice(int i) { } public void onScrubGeo(long l, long l1) { } public void onException(Exception ex) { } public void onStallWarning(StallWarning arg0) { // TODO Auto-generated method stub } }; TwitterStream twitterStream = new TwitterStreamFactory( new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance(); twitterStream.addListener(listener); twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); twitterStream.setOAuthAccessToken(token); if (keyWords.length == 0) { twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); twitterStream.filter(query); } }
From source file:org.sakaiproject.myshowcase.tool.MyShowcaseSaveArtefactTwitterController.java
License:Open Source License
/** * Implementation of AbstractController.handleRequestInternal * @param HttpServletRequest request/*from w ww. j a v a2 s. c o m*/ * @param HttpServletResponse response * @return ModelAndView * @throws Exception */ @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { readRequest(request); Owner owner = myshowcaseService.getOwnerById(new Long(ownerId)); StatusMessage sm = new StatusMessage(); List<StatusMessage> sms = new ArrayList<StatusMessage>(); boolean tweetsFound = true; int totalTweets = 0; int artefactsCount = 0; List<Artefact> artefacts = new ArrayList<Artefact>(); try { Twitter twitter = new TwitterFactory().getInstance(); User user; user = twitter.showUser(aDataValue); int pageNo = 1; int pageSize = 200; int totalMatches = 0; String matchString = aSearchFilter; while (tweetsFound) { Paging paging = new Paging(pageNo, pageSize); ResponseList<Status> statuses = twitter.getUserTimeline(user.getId(), paging); for (Status status : statuses) { if ((matchString.length() == 0) || (status.getText().contains(matchString))) { totalMatches++; Artefact artefact = new Artefact(); ArtefactDetail artefactDetail = new ArtefactDetail(); ArtefactType artefactType = myshowcaseService.getArtefactTypeByName(aType); artefact.setOwner(owner); artefact.setDescription(aDescription); artefact.setName(aTitle); artefact.setShortDesc(aTitle); artefact.setType(artefactType); artefactDetail.setTwitterUserName(aDataValue); artefactDetail.setDetail(status.getText()); artefact.setArtefactDetail(artefactDetail); artefacts.add(artefact); // myshowcaseService.saveArtefact(artefact) ; // artefactsCount++; } } totalTweets += statuses.size(); pageNo++; tweetsFound = (statuses.size() > 0); } } catch (Exception e) { System.out.println("Exception: MyShowcaseSaveArtefactTwitter: " + e.toString()); } if (artefacts.size() > 0) { sm = new StatusMessage("OK", "A total of " + artefacts.size() + " tweets have been added to your evidence stream."); for (Artefact artefact : artefacts) { myshowcaseService.saveArtefact(artefact); } } else { sm = new StatusMessage("ERROR", "MyShowcase has been unable to collect any tweets for your request. No evidence has been added to your evidence stream."); } ; sms.add(sm); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.write(new Gson().toJson(sms)); out.flush(); out.close(); return null; }