List of usage examples for twitter4j User getName
String getName();
From source file:twitterNetwork.twitteridextraction.java
public static void main(String args[]) throws TwitterException { ConfigurationBuilder cb1 = new ConfigurationBuilder(); cb1.setOAuthConsumerKey(consumerKey2); cb1.setOAuthConsumerSecret(consumerSecret2); cb1.setOAuthAccessToken(twitterToken2); cb1.setOAuthAccessTokenSecret(twitterSecret2); Twitter twitter = new TwitterFactory(cb1.build()).getInstance(); User user = twitter.showUser(5108161); System.out.println(user.getName()); System.out.println("<h3>Displaying user id of user " + user.getScreenName() + "</h3><br/>"); System.out.println(user.getId()); }
From source file:twitterrest.Followersids.java
License:Apache License
public static void main(String[] args) throws TwitterException { String ScreenName = "anondroid5";//?? // ?// www.j a v a 2 s .c o m Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY) .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN) .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build(); Twitter twitter = new TwitterFactory(configuration).getInstance(); List<Long> followersList = followers(twitter, ScreenName);//? System.out.println(ScreenName + ":FolloweID List"); for (int i = 0; i < followersList.size(); i++) { System.out.println("[" + (i + 1) + "]" + followersList.get(i)); //? User user = twitter.showUser(followersList.get(i)); System.out.println("User ID : " + user.getId());//UserID System.out.println("ScreenName : " + user.getScreenName());//ScreenName System.out.println("User's Name : " + user.getName());//UserName System.out.println("Number of Followers : " + user.getFollowersCount());//Number of Followers System.out.println("Number of Friends : " + user.getFriendsCount());//Number of Friends System.out.println("Language : " + user.getLang());//Language } }
From source file:ua.group06.presentation.UserLoginTwitter.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request//w w w . j a va 2 s . c om * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Twitter twitter = twitterauth.getTwitter(); RequestToken requestToken = twitterauth.getRequestToken(); //RequestToken requestToken = (RequestToken) request.getSession().getAttribute("requestToken"); String verifier = request.getParameter("oauth_verifier"); System.err.println(twitter + " " + requestToken + " " + verifier); try { AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier); System.err.println(accessToken.getScreenName()); User twitterUser = twitter.showUser(accessToken.getUserId()); String fullName = twitterUser.getName(); String fName = ""; String lName = ""; String[] names = fullName.split(" "); if (names.length == 1) { fName = names[0]; } else if (names.length >= 2) { fName = names[0]; lName = names[names.length - 1]; } ExternalUser user = userService.authenticateOrCreate(accessToken.getScreenName(), "", fName, lName); if (user != null) { HttpSession session = request.getSession(); session.setAttribute("user", user); } //request.getSession().removeAttribute("requestToken"); } catch (TwitterException e) { throw new ServletException(e); } response.sendRedirect("homepage"); }
From source file:uk.ac.cam.cl.dtg.segue.auth.TwitterAuthenticator.java
License:Apache License
@Override public synchronized UserFromAuthProvider getUserInfo(final String internalProviderReference) throws NoUserException, IOException, AuthenticatorSecurityException { Credential credentials = credentialStore.get(internalProviderReference); twitter.setOAuthAccessToken(new AccessToken(credentials.getAccessToken(), credentials.getRefreshToken())); try {/*from w ww.j ava 2 s .c om*/ twitter4j.User userInfo = twitter.verifyCredentials(); if (userInfo != null) { // Using twitter id for email field is a hack to avoid a duplicate // exception due to null email field. Alistair and Steve dislike this... String givenName = null; String familyName = null; if (userInfo.getName() != null) { String[] names = userInfo.getName().split(" "); if (names != null) { if (names.length > 0) { givenName = names[0]; } if (names.length > 1) { familyName = names[1]; } } } return new UserFromAuthProvider(String.valueOf(userInfo.getId()), givenName, familyName, userInfo.getId() + "-twitter", EmailVerificationStatus.NOT_VERIFIED, null, null, null); } else { throw new NoUserException(); } } catch (TwitterException e) { throw new IOException(e.getMessage()); } }
From source file:uk.ac.susx.tag.method51.twitter.Tweet.java
License:Apache License
public Tweet(Status status) { this();//w w w. j a v a 2 s .co m 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 w w . j a v a 2 s .c o m 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()); } } }; }
From source file:uniandes.cupi2.tweetSpy.mundo.TweeSpy.java
License:Academic Free License
/** * Recupera la informacion de los usuarios mencionados. * @throws TwitterException/*from w ww.j a v a 2s .com*/ */ public void cargarMasMencionados() throws TwitterException { ResponseList<Status> menciones = darTimeLine(); for (int i = 0; i < menciones.size(); i++) { Status status = menciones.get(i); UserMentionEntity[] nombreM = status.getUserMentionEntities(); for (int calmese = 0; calmese < nombreM.length; calmese++) { String usuarioMencionado = nombreM[calmese].getScreenName(); User u = user.showUser(usuarioMencionado); Usuario nuevo = new Usuario(u.getName(), u.getOriginalProfileImageURL(), ""); try { arbolMenciones.insertar(nuevo); } catch (YaExisteException e) { nuevo.aumentarContador(); } } } }
From source file:uniandes.cupi2.tweetSpy.mundo.TweeSpy.java
License:Academic Free License
/** * Retorna la lista de amigos del usuario. * @return//from w w w .j a va2s . co m * @throws TwitterException */ public ListaDoblementeEncadenada<Usuario> darListaAmigos() throws TwitterException { listaAmigos = new ListaDoblementeEncadenada<Usuario>(); User u1 = null; long cursor = -1; IDs ids; String resp = user.getScreenName(); do { ids = user.getFriendsIDs(resp, cursor); for (long id : ids.getIDs()) { //System.out.println(id); User useri = user.showUser(id); String nombre = useri.getName(); String name = useri.getScreenName(); String url = useri.getOriginalProfileImageURL(); String desc = useri.getDescription(); //Para buscaar por indices ResponseList<Status> estatuses = user.getUserTimeline(name); Usuario nuevoAmigo = new Usuario(nombre, url, desc); nuevoAmigo.recibirTimeline(estatuses); listaAmigos.agregarFinal(nuevoAmigo); // contenedor? } } while ((cursor = ids.getNextCursor()) != 0); return listaAmigos; }
From source file:uniandes.cupi2.tweetSpy.mundo.TweeSpy.java
License:Academic Free License
/** * Retorna la lista de seguidores del usuario. *///from w w w . j a va 2s.c o m public ListaDoblementeEncadenada<Usuario> darListaSeguidores() throws TwitterException { listaSeguidores = new ListaDoblementeEncadenada<Usuario>(); User u1 = null; long cursor = -1; IDs ids; String resp = user.getScreenName(); do { ids = user.getFollowersIDs(resp, cursor); for (long id : ids.getIDs()) { //System.out.println(id); User useri = user.showUser(id); String nombre = useri.getName(); String url = useri.getOriginalProfileImageURL(); String desc = useri.getDescription(); Usuario nuevoAmigo = new Usuario(nombre, url, desc); listaSeguidores.agregarFinal(nuevoAmigo); // contenedor? } } while ((cursor = ids.getNextCursor()) != 0); return listaSeguidores; }
From source file:User.SearchUsers.java
License:Apache License
public String[] getResults(String name) { try {/*w ww. ja v a 2s. c om*/ Twitter twitter = builder.twitter; int page = 1; int i = 0; ResponseList<User> users; String[] persons = new String[100]; do { users = twitter.searchUsers(name, page); for (User user : users) { String str = ""; if (user != null) { if (user.getName() != null && !user.getName().equals("null") && !user.getName().equals("")) { str = str + user.getName() + ";"; System.out.println(user.getName()); if (user.getLocation() != null) { str = str + user.getLocation() + ";"; } else { str = str + "N/A;"; } if (user.getMiniProfileImageURL() != null) { str = str + user.getProfileImageURL(); } else { str = str + "N/A"; } persons[i] = str; i++; } } } page++; } while (users.size() != 0 && page < 2); return persons; } catch (TwitterException te) { te.printStackTrace(); } return null; }