List of usage examples for twitter4j User getId
long getId();
From source file:org.wandora.application.tools.extractors.twitter.AbstractTwitterExtractor.java
License:Open Source License
public Topic reifyTwitterUser(User user, TopicMap tm) { String userName = user.getName(); String screenName = user.getScreenName(); String userURL = user.getURL(); long uid = user.getId(); String si = TWITTER_USER_SI_BODY + urlEncode(screenName); Topic twitterUserTopic = null;//w w w . j av a2 s .c o m try { twitterUserTopic = tm.getTopic(si); if (twitterUserTopic == null) { twitterUserTopic = tm.createTopic(); twitterUserTopic.addSubjectIdentifier(new Locator(si)); twitterUserTopic.setBaseName(screenName + " (" + uid + ")"); twitterUserTopic.setDisplayName(DEFAULT_LANG, userName); twitterUserTopic.addType(getTwitterUserType(tm)); } } catch (Exception e) { log(e); } return twitterUserTopic; }
From source file:org.wso2.carbon.identity.authenticator.twitter.TwitterAuthenticator.java
License:Open Source License
public void buildClaims(User user, AuthenticationContext context) { AuthenticatedUser authenticatedUserObj; authenticatedUserObj = AuthenticatedUser .createFederateAuthenticatedUserFromSubjectIdentifier(user.getId() + ""); authenticatedUserObj.setAuthenticatedSubjectIdentifier(user.getId() + ""); Map<ClaimMapping, String> claims = new HashMap<ClaimMapping, String>(); claims.put(ClaimMapping.build(TwitterAuthenticatorConstants.TWITTER_CLAIM_NAME, TwitterAuthenticatorConstants.TWITTER_CLAIM_NAME, (String) null, false), user.getName()); claims.put(ClaimMapping.build(TwitterAuthenticatorConstants.TWITTER_CLAIM_EMAIL, TwitterAuthenticatorConstants.TWITTER_CLAIM_EMAIL, (String) null, false), user.getEmail()); authenticatedUserObj.setUserAttributes(claims); context.setSubject(authenticatedUserObj); }
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 va 2 s . co 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 ww w. j a v a 2 s . com // 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 w w.j a 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:Principal.Tracker_Twitter.java
License:Minecraft Mod Public
public void guardarResultados_Twitter(List<ObjetoBuscar> lista, BD base, int contadorBase, int TokenIndice) throws NoSuchAlgorithmException, KeyManagementException { int nuevoContadorBase = 0; if (contadorBase >= lista.size()) { System.out.println("Termino en:" + contadorBase); } else {//from w ww . ja va2s . co m System.out.println("---------------------------------------------------------------------:P"); TrustManager[] trustAllCerts = { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }; SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); System.out.println("Token : " + TokenIndice); System.out.println(consumerKey[TokenIndice]); try { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(consumerKey[TokenIndice]); cb.setOAuthConsumerSecret(this.consumerSecret[TokenIndice]); cb.setOAuthAccessToken(this.token[TokenIndice]); cb.setOAuthAccessTokenSecret(this.tokenSecret[TokenIndice]); Twitter unauthenticatedTwitter = new TwitterFactory(cb.build()).getInstance(); for (int numtTweets = contadorBase; numtTweets < contadorBase + 5; numtTweets++) { if (((ObjetoBuscar) lista.get(numtTweets)).getUrl().equals("") || ((ObjetoBuscar) lista.get(numtTweets)).getUrl() == null) { } else { System.out.println("Usuario: " + ((ObjetoBuscar) lista.get(numtTweets)).getUrl()); String usuariosinArroba = ((ObjetoBuscar) lista.get(numtTweets)).getUrl().replace("@", ""); System.out.println("" + usuariosinArroba); try { User usuario = unauthenticatedTwitter.showUser(usuariosinArroba); List<Status> ret = unauthenticatedTwitter.getRetweetsOfMe(); List<Status> favoritos = unauthenticatedTwitter.getFavorites(); Paging paging = new Paging(1, 1000); ResponseList<Status> statuses = unauthenticatedTwitter.getUserTimeline(usuario.getId(), paging); System.out.println("Followers: " + usuario.getFollowersCount()); System.out.println("Yo sigo: " + usuario.getFriendsCount()); 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(); 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())); } for (int i = 0; i < listaTweets.size(); i++) { base.guardarTrackTwitter_Log((Long) ListaIds.get(i), ((ObjetoBuscar) lista.get(numtTweets)).getUrl(), (String) listaTweets.get(i), (Date) ListaFecha.get(i), (Long) ListaRettewts.get(i), ((Integer) ListaFavoritos.get(i)).intValue(), ((Integer) ListaMenciones.get(i)).intValue()); } } catch (Exception e) { System.err.println("Entro al Try por :" + e); } nuevoContadorBase = numtTweets; } } System.out.println("Numero de Contador Base:" + nuevoContadorBase); guardarResultados_Twitter(lista, base, nuevoContadorBase + 1, TokenIndice + 1); } catch (NumberFormatException e) { System.err.println("Fallo por :" + e); } } }
From source file:stemrps.MentionListener.java
License:Open Source License
@Override public void onStatus(Status status) { System.out.println(status.getUser().getScreenName() + ": " + status.getText()); String[] inp = status.getText().split(" "); String player = ""; if (inp[1].equalsIgnoreCase("stats")) { try {/*from w w w.ja va2 s .c o m*/ long user = status.getUser().getId(); String whoStats = ""; if (inp.length >= 3) { if (inp[2] != null && !inp[2].equalsIgnoreCase("me")) { User acc = STEMrps.t.showUser(inp[2]); user = acc.getId(); whoStats = acc.getScreenName() + " "; } } String tweet = "@" + status.getUser().getScreenName() + " " + whoStats + GameLogic.getStatsString(user); STEMrps.t.updateStatus(tweet); } catch (Exception ex) { Logger.getLogger(MentionListener.class.getName()).log(Level.SEVERE, null, ex); return; } } else { try { if (status.getUser().getId() == 4741197613L) { //If it is our's? return; } STEMrps.makeSureUsrSetup(status.getUser().getId()); for (String s : inp) { if (STEMrps.getFromString(s) != null) { player = s; break; } } stemrps.GameResult match = STEMrps.playGame(status.getUser().getId(), player); String tweet = "@" + status.getUser().getScreenName() + " "; if (match == null) { tweet += "Something went wrong! Please use r, rock, p, paper, s, or scissors to play!"; } else if (match.outcome == stemrps.Status.W) { tweet += "You (" + match.player.name() + ") won against me (" + match.comp.name() + ")"; } else if (match.outcome == stemrps.Status.T) { tweet += "You (" + match.player.name() + ") tied against me (" + match.comp.name() + ")"; } else if (match.outcome == stemrps.Status.L) { tweet += "You (" + match.player.name() + ") lost against me (" + match.comp.name() + ")"; } tweet += " (Game #" + STEMrps.gamesPlayed() + ")"; StatusUpdate rt = new StatusUpdate(tweet); STEMrps.t.updateStatus(rt); } catch (Exception ex) { Logger.getLogger(MentionListener.class.getName()).log(Level.SEVERE, null, ex); String tweet = "@" + status.getUser().getScreenName() + " Oops, did't catch that. " + LocalDateTime.now(); StatusUpdate rt = new StatusUpdate(tweet); try { STEMrps.t.updateStatus(rt); } catch (TwitterException ex1) { Logger.getLogger(MentionListener.class.getName()).log(Level.SEVERE, null, ex1); } } } }
From source file:twitbak.MentionBak.java
License:Open Source License
public void statusToJson(Status status) throws TwitterException, JSONException { JSONObject result = new JSONObject(); User poster = status.getUser(); result.put("Poster ID", poster.getId()); result.put("Poster", poster.getScreenName()); result.put("Poster Name", poster.getName()); result.put("Created At", status.getCreatedAt().toString()); result.put("ID", status.getId()); result.put("Text", status.getText()); long inReplyToStatusId = status.getInReplyToStatusId(); if (inReplyToStatusId != -1) { result.put("In Reply To Status ID", status.getInReplyToStatusId()); }/*ww w.ja v a 2s .c o m*/ long inReplyToUserID = status.getInReplyToUserId(); result.put("In Reply To User ID", inReplyToUserID); if (inReplyToUserID != -1) { result.put("In Reply To Screen Name", status.getInReplyToScreenName()); } boolean isFavorited = status.isFavorited(); if (isFavorited) { result.put("Favorited", status.isFavorited()); } statusArray().put(result); }
From source file:twitbak.TwitBak.java
License:Open Source License
/** * Returns a JSONObject containing user data. * @param user/*from w ww.ja v a 2s . c om*/ * @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.crawler.TwitterCrawler.java
public static void main(String[] args) { try {/*from w ww . j a v a2s. c om*/ // Authorise the library ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey("AhoydO8uSe4v8NEq7j2ISGFlq"); cb.setOAuthConsumerSecret("ptKEYwq3G9vpFkqAhvwFLSWFcBW8U1SfqycECwK4cH6wThVba6"); cb.setOAuthAccessToken("778240255577194496-taafqDIHebrg972oxT5kTqcNd3Uojod"); cb.setOAuthAccessTokenSecret("DMRmeRahnLJRvCBIGQGTaTzE6Pr3PAZMgMsfWIT5ue3PD"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); User user = twitter.verifyCredentials(); // Get main user long cursor = -1; // Print user profile System.out.println("@" + user.getScreenName()); System.out.println(user.getId()); System.out.println(user.getProfileImageURL()); System.out.println(user.getFriendsCount() + " friends."); System.out.println("-------"); // Print Home Timeline List<Status> statuses = twitter.getHomeTimeline(); System.out.println("Showing @" + user.getScreenName() + "'s home timeline."); for (Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } //Print followers System.out.println("-------"); System.out.println("Showing Follwers:"); PagableResponseList<User> followers; //do //{ followers = twitter.getFollowersList(user.getScreenName(), cursor); for (User follower : followers) { System.out.println("@" + follower.getScreenName()); } //} //while ((cursor = followers.getNextCursor())!=-1); //Print follwees System.out.println("-------"); System.out.println("Showing Followees:"); PagableResponseList<User> followees; do { followees = twitter.getFriendsList(user.getScreenName(), cursor); for (User followee : followees) { System.out.println("@" + followee.getScreenName()); } } while ((cursor = followees.getNextCursor()) != -1); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }