List of usage examples for twitter4j User getDescription
String getDescription();
From source file:org.tweetalib.android.model.TwitterUser.java
License:Apache License
public TwitterUser(User user) { mId = user.getId();// w w w . j a v a 2 s . c om mScreenName = user.getScreenName(); mName = user.getName(); mDescription = user.getDescription(); ArrayList<URLEntity> urlEntityArrayList = new ArrayList<URLEntity>(); if (user.getDescriptionURLEntities() != null) { urlEntityArrayList = new ArrayList<URLEntity>(Arrays.asList(user.getDescriptionURLEntities())); } if (user.getURL() != null) { mUrl = user.getURL(); urlEntityArrayList.add(user.getURLEntity()); } mUrlEntities = urlEntityArrayList.toArray(new URLEntity[urlEntityArrayList.size()]); if (user.getLocation() != null && !user.getLocation().equals("")) { mLocation = user.getLocation(); } if (user.getOriginalProfileImageURLHttps() != null) { mProfileImageUrlOriginal = user.getOriginalProfileImageURLHttps(); } if (user.getBiggerProfileImageURLHttps() != null) { mProfileImageUrlBigger = user.getBiggerProfileImageURLHttps(); } if (user.getProfileImageURLHttps() != null) { mProfileImageUrlNormal = user.getProfileImageURLHttps(); } if (user.getMiniProfileImageURLHttps() != null) { mProfileImageUrlMini = user.getMiniProfileImageURLHttps(); } mStatusesCount = user.getStatusesCount(); mFriendsCount = user.getFriendsCount(); mFollowersCount = user.getFollowersCount(); mFavoritesCount = user.getFavouritesCount(); mListedCount = user.getListedCount(); mVerified = user.isVerified(); mProtected = user.isProtected(); mSocialNetType = SocialNetConstant.Type.Twitter; }
From source file:org.xmlsh.twitter.util.TwitterWriter.java
License:BSD License
private void write(String localName, User user) throws XMLStreamException { startElement("user"); attribute("created-at", user.getCreatedAt()); attribute("description", user.getDescription()); attribute("favorites-count", user.getFavouritesCount()); user.getFollowersCount();/*from w w w. j a v a2 s .c o m*/ user.getFriendsCount(); attribute("id", sanitizeID(user.getId())); attribute("lang", user.getLang()); user.getListedCount(); attribute("name", sanitizeUser(user.getName())); user.getProfileBackgroundColor(); user.getProfileBackgroundImageUrl(); user.getProfileBackgroundImageUrlHttps(); user.getProfileImageURL(); user.getProfileImageUrlHttps(); user.getProfileLinkColor(); user.getProfileSidebarBorderColor(); user.getProfileTextColor(); user.getRateLimitStatus(); attribute("screen-name", sanitizeUser(user.getScreenName())); user.getStatusesCount(); user.getTimeZone(); user.getURL(); user.getUtcOffset(); write("location", user.getLocation()); write("user-status", user.getStatus()); endElement(); }
From source file:peoplesearch.FindFriendsAndFollowers.java
public void GetFollowersIDs() { try {//from w w w . ja v a2 s . c o m // I need to pass the Person name and the TwitterID. //String targetname="Philip Bergkvist"; Twitter twitter = new TwitterFactory().getInstance(); long cursor = -1; IDs ids; ResponseList<User> users1 = null; ResponseList<User> users2 = null; System.out.println("Listing followers's ids."); GraphManager mgr = EmbeddedGraphManager.getInstance(); mgr.init(new File("/usr/local/Cellar/neo4j/2.1.7/libexec/data/forlang1.db")); //mgr.addTwitterAccount(new TwitterAccountImpl(new Date(), "I am Studying", 13, 82, true,"Aalborg", "Philiptwoshoes", 2730631792L)); List<TwitterAccount> twitteraccountslist; twitteraccountslist = null; twitteraccountslist = mgr.listTwitterAccounts(); System.out.println("the number of twitter account in the neo4J DB is" + twitteraccountslist.size()); for (TwitterAccount Twit : twitteraccountslist) { do { TwitterLimitWait tlw = new TwitterLimitWait(); tlw.CheckLimit(); if (0 < twitteraccountslist.size()) { ids = twitter.getFollowersIDs(Twit.getScreenName(), cursor); //.getFollowersIDs(pep[0], cursor); //ids = twitter.getFollowersIDs("Philiptwoshoes", cursor); //.getFollowersIDs(pep[0], cursor); tlw.CheckLimit(); users1 = twitter.getFollowersList(Twit.getScreenName(), cursor); tlw.CheckLimit(); users2 = twitter.getFriendsList(Twit.getScreenName(), cursor); } else { tlw.CheckLimit(); ids = twitter.getFollowersIDs(cursor); } for (User user : users1) { tlw.CheckLimit(); System.out.println("the follower called " + user.getName() + " with twitter handler " + user.getScreenName()); String username = user.getName(); //mgr.addPerson(new PersonImpl(username)); Date Creation = user.getCreatedAt(); tlw.CheckLimit(); String descript = user.getDescription(); boolean empty1 = user.getDescription().isEmpty(); if (empty1 == true) { descript = " "; } tlw.CheckLimit(); int followers = user.getFollowersCount(); tlw.CheckLimit(); int following = user.getFriendsCount(); boolean geo = user.isGeoEnabled(); String loc = user.getLocation(); boolean empty2 = user.getLocation().isEmpty(); if (empty2 == true) { loc = " "; } String screenname = user.getScreenName(); boolean empty3 = user.getScreenName().isEmpty(); if (empty3 == true) { screenname = " "; } tlw.CheckLimit(); long twitID = user.getId(); mgr.linkPersonToTwitterAccount(new PersonImpl(username), new TwitterAccountImpl(Creation, descript, followers, following, geo, loc, screenname, twitID)); mgr.linkTwitterAccounts(new TwitterAccountImpl(Creation, descript, followers, following, geo, loc, screenname, twitID), Twit); } System.out.println("The total number of followers is: " + users1.size()); // the same procedure for the Following for (User user : users2) { tlw.CheckLimit(); System.out.println("the following called " + user.getName() + " with twitter handler " + user.getScreenName()); String username1 = user.getName(); //mgr.addPerson(new PersonImpl(username1)); Date Creation = user.getCreatedAt(); String descript = user.getDescription(); boolean empty1 = user.getDescription().isEmpty(); if (empty1 == true) { descript = " "; } int followers = user.getFollowersCount(); int following = user.getFriendsCount(); boolean geo = user.isGeoEnabled(); String loc = user.getLocation(); boolean empty2 = user.getLocation().isEmpty(); if (empty2 == true) { loc = " "; } String screenname = user.getScreenName(); tlw.CheckLimit(); boolean empty3 = user.getScreenName().isEmpty(); if (empty3 == true) { screenname = " "; } tlw.CheckLimit(); long twitID = user.getId(); //mgr.addTwitterAccount(new TwitterAccountImpl(Creation,descript,followers,following,geo,loc,screenname,twitID)); mgr.linkPersonToTwitterAccount(new PersonImpl(username1), new TwitterAccountImpl(Creation, descript, followers, following, geo, loc, screenname, twitID)); mgr.linkTwitterAccounts(Twit, new TwitterAccountImpl(Creation, descript, followers, following, geo, loc, screenname, twitID)); } System.out.println("The total number of friend is: " + users2.size()); //} } while ((cursor = ids.getNextCursor()) != 0); } mgr.destroy(); // I have to check that the second iteration works fine, because i could not test that. System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get followers' ids: " + te.getMessage()); System.exit(-1); } }
From source file:peoplesearch.SearchTwitterUsers.java
public void SearchTwitterUsers() { int page = 1; int numberofpages = 0; Date TwitterAccCreatedAt = new Date(); String TwitterAccDescr = " "; int TwitterFollowersCount = 0; int TwitterFriendsCount = 0; boolean TwitterGeoEnabled = false; String TwitterLocation = " "; String TwiterAccScrName = " "; long TwitterID = 0L; try {/* w ww. ja v a 2 s . c o m*/ Twitter twitter = new TwitterFactory().getInstance(); ResponseList<User> users; List<Person> people = null; GraphManager mgr = EmbeddedGraphManager.getInstance(); mgr.init(new File("/usr/local/Cellar/neo4j/2.1.7/libexec/data/forlang1.db")); mgr.addPerson(new PersonImpl("wgaura")); mgr.addPerson(new PersonImpl("Derek Mizak")); mgr.addPerson(new PersonImpl("Swiderek")); mgr.addPerson(new PersonImpl("Microsoft")); mgr.addPerson(new PersonImpl("BBC")); mgr.addPerson(new PersonImpl("RTE")); mgr.addPerson(new PersonImpl("CNBC")); mgr.addPerson(new PersonImpl("Poland")); mgr.addPerson(new PersonImpl("Ireland")); mgr.addPerson(new PersonImpl("Ergo")); people = mgr.listPeople(); for (Person person : people) { do { TwitterLimitWait tlw = new TwitterLimitWait(); tlw.CheckLimit(); users = twitter.searchUsers(person.getName(), page); numberofpages = users.size() / 20; for (User user : users) { if (user.getStatus() != null) { TwitterAccCreatedAt = user.getCreatedAt(); if (!user.getDescription().isEmpty()) { TwitterAccDescr = user.getDescription(); } //if (user.getFollowersCount()>0) {TwitterFollowersCount=user.getFavouritesCount();} //if (user.getFriendsCount()>0) {TwitterFriendsCount=user.getFriendsCount();} TwitterFollowersCount = user.getFollowersCount(); TwitterFriendsCount = user.getFriendsCount(); TwitterGeoEnabled = user.isGeoEnabled(); if (!user.getLocation().isEmpty()) { TwitterLocation = user.getLocation(); } TwiterAccScrName = user.getScreenName(); TwitterID = user.getId(); System.out.println("@" + user.getScreenName() + " - " + TwitterFollowersCount + " _ " + TwitterFriendsCount); //mgr.addTwitterAccount(new TwitterAccountImpl(TwitterAccCreatedAt,TwitterAccDescr,TwitterFollowersCount,TwitterFriendsCount,TwitterGeoEnabled,TwitterLocation,TwiterAccScrName,TwitterID)); mgr.linkPersonToTwitterAccount(person, new TwitterAccountImpl(TwitterAccCreatedAt, TwitterAccDescr, TwitterFollowersCount, TwitterFriendsCount, TwitterGeoEnabled, TwitterLocation, TwiterAccScrName, TwitterID)); TwitterAccDescr = " "; TwitterLocation = " "; TwitterFollowersCount = 0; TwitterFriendsCount = 0; //numberofusers++; } else { // the user is protected System.out.println("@" + user.getScreenName()); } } page++; //System.out.println(page); } while (users.size() != 0 && page < numberofpages); } } catch (Exception ex) { System.out.println(ex.getMessage()); } }
From source file:twitbak.TwitBak.java
License:Open Source License
/** * Returns a JSONObject containing user data. * @param user//w ww . j av a 2s . co m * @return * @throws TwitterException * @throws JSONException */ //TODO - should be void to match other Bak classes static JSONObject userToJson(User user) throws TwitterException, JSONException { JSONObject result = new JSONObject(); JSONObject userData = new JSONObject(); userData.put("ID", user.getId()); userData.put("Screen Name", user.getScreenName()); userData.put("Name", user.getName()); userData.put("Description", user.getDescription()); userData.put("Profile Image URL", user.getProfileImageURL()); userData.put("URL", user.getURL()); userData.put("Protected", user.isProtected()); userData.put("Followers", user.getFollowersCount()); userData.put("Created At", user.getCreatedAt().toString()); userData.put("Favorites", user.getFavouritesCount()); userData.put("Friends", user.getFriendsCount()); userData.put("Location", user.getLocation()); userData.put("Statuses", user.getStatusesCount()); userData.put("Profile Background Color", user.getProfileBackgroundColor()); userData.put("Profile Background Image URL", user.getProfileBackgroundImageUrl()); userData.put("Profile Sidebar Border Color", user.getProfileSidebarBorderColor()); userData.put("Profile Sidebar Fill Color", user.getProfileSidebarFillColor()); userData.put("Profile Text Color", user.getProfileTextColor()); userData.put("Time Zone", user.getTimeZone()); result.put("User data", userData); return result; }
From source file:twitter.metrics.TwitterMetrics.java
/** * @param args the command line arguments */// ww w. j a va 2 s .c o m public static void main(String[] args) { try { /*Parte que guarda en un archivo*/ // Se crea el libro HSSFWorkbook libro = new HSSFWorkbook(); // Se crea una hoja dentro del libro HSSFSheet hoja = libro.createSheet(); // Se crea una fila dentro de la hoja HSSFRow fila = hoja.createRow(0); // Se crea una celda dentro de la fila HSSFCell celda = fila.createCell(1); // Se crea el contenido de la celda y se mete en ella. HSSFRichTextString texto = new HSSFRichTextString("Metricas de Twitter"); celda.setCellValue(texto); /************************************/ /*Conexion con Mongo DB*/ MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("JavaMongoTwitter"); DBCollection datos = db.getCollection("Datos"); /***********************/ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey("TobUISZXWUhDda04ZBtFGQ"); cb.setOAuthConsumerSecret("7xurVN3iP6VDcBfKdFJxVuNsJjExERFYNmQIDgtg"); cb.setOAuthAccessToken("849956971-GJBiORhLIuWK4i3MJ2YCd4vidh65N1GzPIb6duXk"); cb.setOAuthAccessTokenSecret("4MJgPS9grxVuKbczrPCdSjNnumhcWs7t7OLy2F4kkpOdu"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); User u = twitter.showUser("Pringles"); System.out.println("Nombre: " + u.getName()); System.out.println("Seguidores: " + u.getFollowersCount()); System.out.println("Favoritos: " + u.getFavouritesCount()); System.out.println("Seguidos: " + u.getFriendsCount()); System.out.println("Ubicacion: " + u.getLocation()); System.out.println("Descripcin: " + u.getDescription()); System.out.println(""); fila = hoja.createRow(1); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Nombre:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getName())); fila = hoja.createRow(2); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Seguidores:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getFollowersCount() + "")); fila = hoja.createRow(3); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Favoritos:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getFavouritesCount() + "")); fila = hoja.createRow(4); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Seguidos:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getFriendsCount() + "")); fila = hoja.createRow(5); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Ubicacin:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getLocation() + "")); fila = hoja.createRow(6); celda = fila.createCell(0); celda.setCellValue(new HSSFRichTextString("Descripcin:")); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(u.getDescription() + "")); fila = hoja.createRow(7); celda = fila.createCell(3); celda.setCellValue(new HSSFRichTextString("Tweets!!!")); fila = hoja.createRow(9); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString("IdTweet")); celda = fila.createCell(2); celda.setCellValue(new HSSFRichTextString("Cuenta")); celda = fila.createCell(3); celda.setCellValue(new HSSFRichTextString("Tweet")); celda = fila.createCell(4); celda.setCellValue(new HSSFRichTextString("Geolocation")); celda = fila.createCell(5); celda.setCellValue(new HSSFRichTextString("Place")); celda = fila.createCell(6); celda.setCellValue(new HSSFRichTextString("Retweets")); celda = fila.createCell(7); celda.setCellValue(new HSSFRichTextString("Favoritos")); Paging paging = new Paging(1, 1000); ResponseList<Status> s = twitter.getUserTimeline(u.getId(), paging); int i = 0; int filaNum = 10; for (Status st : s) { BasicDBObject obj = new BasicDBObject(); obj.append("idTweet", s.get(i).getId() + ""); obj.append("Cuenta", u.getName()); obj.append("Tweet", s.get(i).getText()); obj.append("Geolocation", s.get(i).getGeoLocation()); obj.append("Place", s.get(i).getPlace()); obj.append("Reteews", s.get(i).getRetweetCount()); obj.append("Favoritos", s.get(i).getFavoriteCount()); fila = hoja.createRow(filaNum); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(s.get(i).getId() + "")); celda = fila.createCell(2); celda.setCellValue(new HSSFRichTextString(u.getName())); celda = fila.createCell(3); celda.setCellValue(new HSSFRichTextString(s.get(i).getText())); celda = fila.createCell(4); celda.setCellValue(new HSSFRichTextString(s.get(i).getGeoLocation() + "")); celda = fila.createCell(5); celda.setCellValue(new HSSFRichTextString(s.get(i).getPlace() + "")); celda = fila.createCell(6); celda.setCellValue(new HSSFRichTextString(s.get(i).getRetweetCount() + "")); celda = fila.createCell(7); celda.setCellValue(new HSSFRichTextString(s.get(i).getFavoriteCount() + "")); i++; filaNum++; datos.insert(obj); } FileOutputStream elFichero = new FileOutputStream("Metricas_Twitter.xls"); libro.write(elFichero); elFichero.close(); /********************************/ System.out.println(i); //User usuario = twitter.showUser("@aaron21007"); // List<Status> statuses = twitter.getHomeTimeline(); // System.out.println("Showing home timeline."); // for (Status status : statuses) { // System.out.println(status.getUser().getName() + ":" + // status.getText()); // } // Twitter unauthenticatedTwitter = new TwitterFactory(cb.build()).getInstance(); // // List<String> listaTweets = new ArrayList(); // List<Long> ListaRettewts = new ArrayList(); // List<Integer> ListaFavoritos = new ArrayList(); // List<Integer> ListaMenciones = new ArrayList(); // List<Date> ListaFecha = new ArrayList(); // List<Long> ListaIds = new ArrayList(); //// // User usuario = unauthenticatedTwitter.showUser("@aaron21007"); // List<Status> ret = unauthenticatedTwitter.getRetweetsOfMe(); // List<Status> favoritos = unauthenticatedTwitter.getFavorites(); // Paging paging = new Paging(1, 1000); // ResponseList<Status> statuses = unauthenticatedTwitter.getUserTimeline(usuario.getId(), paging); // // // for (Status sta : statuses) { // // ListaIds.add(Long.valueOf(sta.getId())); // listaTweets.add(sta.getText()); // ListaRettewts.add(Long.valueOf(Long.parseLong(sta.getRetweetCount() + ""))); // ListaMenciones.add(Integer.valueOf(sta.getUserMentionEntities().length)); // ListaFecha.add(sta.getCreatedAt()); // ListaFavoritos.add(Integer.valueOf(sta.getFavoriteCount())); // System.out.println(sta.getText()); // // } // // // // // } catch (Exception e) { System.err.println("Fallo................." + e); } }
From source file:TwitterDownload.TwitterExel.java
public static String writeFollowers(long ID, List<User> followers, String path) { try {/*from w w w .j a v a 2s . c o m*/ path = path + "Tweets"; File theDir = new File(path); // if the directory does not exist, create it if (!theDir.exists()) { theDir.mkdir(); } String exlPath = path + "/" + ID + ".xls"; File exlFile = new File(exlPath); WritableWorkbook writableWorkbook = null; WritableSheet writableSheet = null; int i = 0; while (exlFile.exists()) { i++; exlPath = path + "/" + ID + "_" + i + ".xls"; exlFile = new File(exlPath); } writableWorkbook = Workbook.createWorkbook(exlFile); writableSheet = writableWorkbook.createSheet("FerretData", 0); try { Workbook existing = Workbook.getWorkbook(exlFile); writableWorkbook = Workbook.createWorkbook(exlFile, existing); writableSheet = writableWorkbook.getSheet(0); } catch (BiffException be) { } //Create Cells with contents of different data types. //Also specify the Cell coordinates in the constructor i = 0; i = writableSheet.getRows(); if (i == 0) { Label userName = new Label(0, 0, "User Name"); Label name = new Label(1, 0, "Name"); Label desc = new Label(2, 0, "Description"); Label date = new Label(3, 0, "Created Date"); Label uID = new Label(4, 0, "Twitter ID"); Label link = new Label(5, 0, "Link"); //Add the created Cells to the sheet writableSheet.addCell(userName); writableSheet.addCell(name); writableSheet.addCell(desc); writableSheet.addCell(date); writableSheet.addCell(uID); writableSheet.addCell(link); i = 1; } for (int j = 0; j < followers.size(); j++) { User u = followers.get(j); Label userName = new Label(0, i + j, u.getScreenName()); Label name = new Label(1, i + j, u.getName()); Label desc = new Label(2, i + j, u.getDescription()); DateTime date = new DateTime(3, i + j, u.getCreatedAt()); Label uID = new Label(4, i + j, Long.toString(u.getId())); String link = "https://twitter.com/" + u.getScreenName(); URL url = new URL(link); WritableHyperlink hl = new WritableHyperlink(5, j + 1, url); //Add the created Cells to the sheet writableSheet.addCell(userName); writableSheet.addCell(name); writableSheet.addCell(desc); writableSheet.addCell(date); writableSheet.addCell(uID); writableSheet.addHyperlink(hl); } //Write and close the workbook writableWorkbook.write(); writableWorkbook.close(); return exlPath; } catch (IOException e) { e.printStackTrace(); } catch (RowsExceededException e) { e.printStackTrace(); } catch (WriteException e) { e.printStackTrace(); } return null; }
From source file:TwitterLookUpUsers.LookupUsers.java
License:Apache License
public static void main(String[] args) throws InterruptedException { Postgresql.DBBaglan();//from ww w . j a va 2s . c om Postgresql.DBSelect(); Twitter twitter = new TwitterFactory().getInstance(); for (int j = 0; j < sonuc.length; j++) { try { User user = twitter.showUser(sonuc[j]); if (user.getStatus() != null) { System.out.println((j + 1) + ". Sorgu___________________________________"); System.out.println("@" + user.getScreenName()); System.out.println(user.getTimeZone()); System.out.println("@" + user.getName()); System.out.println("@" + user.getURL()); System.out.println("LOKASYONN : " + user.getLocation()); System.out.println("@" + user.getDescription()); System.out.println("@" + user.getOriginalProfileImageURL()); System.out.println("@" + user.getMiniProfileImageURL()); System.out.println("@" + user.getProfileBackgroundImageURL()); System.out.println("_______________________________________________"); if (lokasyon[j].contains(user.getLocation())) { System.out.println("KULLANICI BU OLABLR*************************"); } } else { // the user is protected System.out.println((j + 1) + ". Sorgu______________________________________"); System.out.println("@" + user.getScreenName() + "---- KULLANICI PUBLIC DEL"); System.out.println("___________________________________________________"); } } catch (TwitterException te) { te.printStackTrace(); if ((te.getErrorCode() == 88)) { System.err.println("EXCEED.............."); Thread.sleep(900000); //wait 15 min } System.out.println(); } } System.exit(0); }
From source file:uk.ac.susx.tag.method51.twitter.Tweet.java
License:Apache License
public Tweet(Status status) { this();//from w w w . j a v a2 s .c om created = status.getCreatedAt(); id = status.getId(); text = status.getText(); inReplyToStatusId = status.getInReplyToStatusId(); inReplyToUserId = status.getInReplyToUserId(); originalText = null; retweetId = -1; isTruncated = status.isTruncated(); isRetweet = status.isRetweet(); Status entities = status; if (isRetweet) { Status origTweet = status.getRetweetedStatus(); entities = origTweet; retweetId = origTweet.getId(); originalText = text; text = origTweet.getText(); } StringBuilder sb = new StringBuilder(); for (HashtagEntity e : entities.getHashtagEntities()) { sb.append(e.getText()); sb.append(" "); } hashtags = sb.toString(); sb = new StringBuilder(); for (UserMentionEntity e : entities.getUserMentionEntities()) { sb.append(e.getScreenName()); sb.append(" "); } mentions = sb.toString(); sb = new StringBuilder(); for (URLEntity e : entities.getURLEntities()) { //String url = e.getURL(); String url = e.getExpandedURL(); if (url == null) { url = e.getURL(); if (url != null) { sb.append(url); } } else { sb.append(url); } sb.append(" "); } urls = sb.toString(); sb = new StringBuilder(); //seems to be null if no entries MediaEntity[] mediaEntities = entities.getMediaEntities(); if (mediaEntities != null) { for (MediaEntity e : mediaEntities) { String url = e.getMediaURL(); sb.append(url); sb.append(" "); } mediaUrls = sb.toString(); } else { mediaUrls = ""; } received = new Date(); source = status.getSource(); GeoLocation geoLoc = status.getGeoLocation(); Place place = status.getPlace(); if (geoLoc != null) { geoLong = geoLoc.getLongitude(); geoLat = geoLoc.getLatitude(); } else if (place != null && place.getBoundingBoxCoordinates() != null && place.getBoundingBoxCoordinates().length > 0) { GeoLocation[] locs = place.getBoundingBoxCoordinates()[0]; double avgLat = 0; double avgLon = 0; for (GeoLocation loc : locs) { avgLat += loc.getLatitude(); avgLon += loc.getLongitude(); } avgLat /= locs.length; avgLon /= locs.length; geoLat = avgLat; geoLong = avgLon; } else { geoLong = null; geoLat = null; } twitter4j.User user = status.getUser(); if (user != null) { userId = user.getId(); location = user.getLocation(); screenName = user.getScreenName(); following = user.getFriendsCount(); name = user.getName(); lang = user.getLang(); timezone = user.getTimeZone(); userCreated = user.getCreatedAt(); followers = user.getFollowersCount(); statusCount = user.getStatusesCount(); description = user.getDescription(); url = user.getURL(); utcOffset = user.getUtcOffset(); favouritesCount = user.getFavouritesCount(); this.user = new User(user); } }
From source file:uk.ac.susx.tag.method51.webapp.handler.TwitterPinAuthHandler.java
License:Apache License
private void getUserInfo(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { final Params params = new Params(); params.addValidator("id", new SystemStringValidator(true)); new DoSomethingAfterValidatingMyParams(params, request, response) { @Override//from w ww. ja v a 2 s. com public void something() throws IOException { final String id = request.getParameter("id"); final Twitter twitter = newTwitterInstance(ApiKeyStore.getKey(id)); try { final AccountSettings as = twitter.getAccountSettings(); final String userScreenName = twitter.getScreenName(); final long userId = twitter.getId(); final User user = twitter.showUser(userId); okHereIsYourJson(response, "name", user.getName(), "description", user.getDescription(), "created", user.getCreatedAt(), "favourites_count", user.getFavouritesCount(), "followers_count", user.getFollowersCount(), "friends_count", user.getFriendsCount(), "profile_image_url", user.getProfileImageURL(), "screen_name", userScreenName, "user_id", userId, "language", as.getLanguage(), "sleep_time_enabled", as.isSleepTimeEnabled(), "sleep_end_time", as.getSleepEndTime(), "sleep_start_time", as.getSleepStartTime(), "timezone", as.getTimeZone(), "trend_locations", as.getTrendLocations(), "always_use_https", as.isAlwaysUseHttps(), "discoverable_by_email", as.isDiscoverableByEmail(), "geo_enabled", as.isGeoEnabled()); } catch (TwitterException e) { LOG.warn("Failed to retrieve users data.", e); error(e.getMessage()); } } }; }