List of usage examples for twitter4j Status getUser
User getUser();
From source file:org.wso2.carbon.connector.twitter.TwitterRetweetStatus.java
License:Open Source License
public void connect(MessageContext messageContext) throws ConnectException { try {/*w ww .j av a 2 s . c o m*/ String id = TwitterUtils.lookupTemplateParamater(messageContext, ID); Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); Status status = twitter.retweetStatus(Long.parseLong(id)); TwitterUtils.storeResponseStatus(messageContext, status); if (log.isDebugEnabled()) { log.info("@" + status.getUser().getScreenName() + " - " + status.getText()); } } catch (TwitterException te) { log.error("Failed to retweet status: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.wso2.carbon.connector.twitter.TwitterUtils.java
License:Open Source License
public static void storeResponseStatus(MessageContext ctxt, Status status) { ctxt.setProperty(TwitterConnectConstants.TWITTER_STATUS_USER_SCREEN_NAME, status.getUser().getScreenName()); ctxt.setProperty(TwitterConnectConstants.TWITTER_STATUS_STATUS_TEXT, status.getText()); ctxt.setProperty(TwitterConnectConstants.TWITTER_API_RESPONSE, status); }
From source file:org.xmlsh.twitter.util.TwitterWriter.java
License:BSD License
public void write(Status t) throws XMLStreamException { startElement("tweet"); attribute("id", t.getId()); // write("annotations",t.getAnnotations()); write("created-at", t.getCreatedAt()); write("from-user", sanitizeID(t.getUser().getId()), sanitizeUser(t.getUser().getName())); write("geo-location", t.getGeoLocation()); write("hash-tags", t.getHashtagEntities()); write("iso-language-code", t.getUser().getLang()); write("location", t.getUser().getLocation()); write("media", t.getMediaEntities()); write("place", t.getPlace()); write("profile-image-url", sanitizeUser(t.getUser().getProfileImageURL())); write("source", t.getSource()); write("text", t.getText()); write("to-user", sanitizeID(t.getInReplyToUserId()), sanitizeUser(t.getInReplyToScreenName())); write("url-entities", t.getURLEntities()); write("user-mention-entities", t.getUserMentionEntities()); endElement();/* w w w . j ava 2s. co m*/ }
From source file:org.xmlsh.twitter.util.TwitterWriter.java
License:BSD License
public void write(String localName, Status status) throws XMLStreamException { if (status != null) { startElement(localName);// www.ja va 2 s .co m attribute("id", status.getId()); // write("annotations",t.getAnnotations()); write("created-at", status.getCreatedAt()); write("user", status.getUser()); write("geo-location", status.getGeoLocation()); write("hash-tags", status.getHashtagEntities()); write("media", status.getMediaEntities()); write("place", status.getPlace()); write("source", status.getSource()); write("text", status.getText()); write("url-entities", status.getURLEntities()); write("user-mention-entities", status.getUserMentionEntities()); endElement(); } }
From source file:org.zoneproject.extractor.twitterreader.TwitterApi.java
License:Open Source License
/** * create an item by his twitter Status description, will add hashtags and others "metas" * @param s the twitter Status//ww w . j av a 2s.c o m * @param source the Uri of the source * @return the item created */ private static Item getItemFromStatus(Status s, String source) { String text = s.getText(); if (s.isRetweet()) { text = s.getRetweetedStatus().getText(); } Item res = new Item(source, "https://twitter.com/" + s.getUser().getScreenName() + "/status/" + Long.toString(s.getId()), text, text, s.getCreatedAt()); String[] hashtags = getHashTags(res.getDescription()); for (String hashtag : hashtags) { res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_HASHTAG, hashtag, true, true)); } for (String mentioned : TwitterApi.extractor.extractMentionedScreennames(s.getText())) { res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_MENTIONED, "@" + mentioned, true, true)); } if (s.getGeoLocation() != null) { res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_POSITION_LONGITUDE, Double.toString(s.getGeoLocation().getLongitude()), true, true)); res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_POSITION_LATITUDE, Double.toString(s.getGeoLocation().getLatitude()), true, true)); } res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_AUTHOR, "@" + s.getUser().getScreenName(), true, true)); return res; }
From source file:Origin.Mypage.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TwitterException { response.setContentType("text/html;charset=UTF-8"); /* TODO output your page here. You may use following sample code. */ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);// w w w .j av a2 s .co m cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuthAccessToken(ACCESS_TOKEN); cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); User user = twitter.verifyCredentials(); request.setCharacterEncoding("UTF-8"); HttpSession hs = request.getSession(); UserData ud = (UserData) hs.getAttribute("ud"); String search = ud.getLine() + "?"; //String search= request.getParameter("searchtweet"); Query query = new Query(); query.setCount(100); query.setQuery(search); QueryResult queryresult = null; try { queryresult = twitter.search(query); } catch (TwitterException e1) { e1.printStackTrace(); } ArrayList<String> userID = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { userID.add(tweet.getUser().getScreenName()); } ArrayList<String> profileimg = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { profileimg.add(tweet.getUser().getBiggerProfileImageURL()); } ArrayList<String> username = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getName() + "<br>" + "@" + tweet.getUser().getScreenName()); } ArrayList<String> usernameURL = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getURL()); } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); ArrayList<String> resulttweet = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { resulttweet.add(tweet.getText() + "<br>" + sdf.format(tweet.getCreatedAt())); } request.setAttribute("search", search); request.setAttribute("userID", userID); request.setAttribute("profileimg", profileimg); request.setAttribute("username", username); request.setAttribute("resulttweet", resulttweet); request.setAttribute("usernameURL", usernameURL); request.getRequestDispatcher("/mypage.jsp").forward(request, response); }
From source file:Origin.Searchtweet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TwitterException { response.setContentType("text/html;charset=UTF-8"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);/*from w w w . j a va 2 s .c om*/ cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuthAccessToken(ACCESS_TOKEN); cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); User user = twitter.verifyCredentials(); request.setCharacterEncoding("UTF-8"); String search = "?" + request.getParameter("searchtweet"); //String search= request.getParameter("searchtweet"); Query query = new Query(); query.setCount(100); query.setQuery(search); QueryResult queryresult = null; try { queryresult = twitter.search(query); } catch (TwitterException e1) { e1.printStackTrace(); } ArrayList<String> userID = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { userID.add(tweet.getUser().getScreenName()); } ArrayList<String> profileimg = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { profileimg.add(tweet.getUser().getBiggerProfileImageURL()); } ArrayList<String> username = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getName() + "<br>" + "@" + tweet.getUser().getScreenName()); } ArrayList<String> usernameURL = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { username.add(tweet.getUser().getURL()); } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); ArrayList<String> resulttweet = new ArrayList<>(); for (Status tweet : queryresult.getTweets()) { resulttweet.add(tweet.getText() + "<br>" + sdf.format(tweet.getCreatedAt())); } request.setAttribute("search", search); request.setAttribute("userID", userID); request.setAttribute("profileimg", profileimg); request.setAttribute("username", username); request.setAttribute("resulttweet", resulttweet); request.setAttribute("usernameURL", usernameURL); request.getRequestDispatcher("/searchtweet.jsp").forward(request, response); }
From source file:proxectotwitt.Metodo.java
/** * Con esto visualizaremos todos nuestros twitts publicados *//*w ww .j a v a 2s.c o m*/ public static void timeLine() { List<Status> statuses; try { statuses = twitter.getHomeTimeline(); System.out.println("Enseando timeline."); for (twitter4j.Status status : statuses) { System.out.println(status.getUser().getName() + ":" + status.getText()); twits.add(status); } } catch (TwitterException ex) { java.util.logging.Logger.getLogger(Metodo.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:proxectotwitt.Metodo.java
/** * Pasaremos el paremetro buscar para buscar todos los twits con esa palabra * @param buscar /*w ww.jav a 2s . c o m*/ */ public static void buscar(String buscar) { QueryResult result; try { Query query = new Query(JOptionPane.showInputDialog("Hashtag a buscar: ")); result = twitter.search(query); for (twitter4j.Status statuse : result.getTweets()) { System.out.println("@" + statuse.getUser().getScreenName() + ":" + statuse.getText()); } } catch (TwitterException ex) { java.util.logging.Logger.getLogger(Metodo.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:proyectotwitter.AppTwitter.java
public void buscar(String text) { try {/*from w w w. j a v a 2 s . c o m*/ Query query = new Query("#" + text); QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); } } catch (TwitterException ex) { System.out.println("Error al buscar"); } }