Example usage for twitter4j User getLocation

List of usage examples for twitter4j User getLocation

Introduction

In this page you can find the example usage for twitter4j User getLocation.

Prototype

String getLocation();

Source Link

Document

Returns the location of the user

Usage

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();/* w  w  w.  j  a v  a2  s  .com*/
    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 {//  ww w. ja  v a2  s .c  om
        // 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.java 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:tweetcrawling.TweetCrawler.java

public ArrayList<String> getValueToWrite(Status status) {

    // Getting the value to be written

    Long tid = status.getId();/*w  w w.  j  av  a 2 s .c om*/
    String tweetid = tid.toString();

    ArrayList<String> valueToWrite = new ArrayList<String>();

    User user = status.getUser();
    String screenname = user.getScreenName();
    String name = user.getName();
    String url = getTweetUrl(screenname, tweetid);

    String body = status.getText().replace("\n", " ");

    valueToWrite.add(body.replace(",", " ")); // element: body
    valueToWrite.add(url); // element: id
    valueToWrite.add(screenname); // element: userid
    valueToWrite.add(name); // element: user

    // element: gender
    if (name != null && !name.isEmpty()) {
        valueToWrite.add(getUserGender(name));
    } else if (screenname != null && !screenname.isEmpty()) {
        valueToWrite.add(getUserGender(screenname));
    } else {
        valueToWrite.add("");
    }

    valueToWrite.add(user.getLocation()); // element: location
    valueToWrite.add("" + user.getFollowersCount()); // element: followercount
    valueToWrite.add("" + user.getFriendsCount()); // element: friendscount
    valueToWrite.add("" + user.getStatusesCount()); // element: statuscount

    try {
        List<String> coor = new ArrayList<String>();
        String latitude = "" + status.getGeoLocation().getLatitude();
        String longitude = "" + status.getGeoLocation().getLongitude();
        coor.add(latitude);
        coor.add(longitude);

        if (coor != null && !coor.isEmpty() && coor.size() > 0) {
            valueToWrite.add(coor.get(0)); // element: latitude
            valueToWrite.add(coor.get(1)); // element: longitude
            valueToWrite.add(coor.get(0) + "," + coor.get(1));
        } else {
            valueToWrite.add(null);
            valueToWrite.add(null);
            valueToWrite.add(null);
        }
    } catch (Exception e) {
        valueToWrite.add(null);
        valueToWrite.add(null);
        valueToWrite.add(null);
    }

    try {

        String geoname = status.getPlace().getName();
        String country = status.getPlace().getCountry();

        if (geoname != null) {
            valueToWrite.add(geoname);
        } else {
            valueToWrite.add(null);
        }

        if (country != null) {
            valueToWrite.add(country);
        } else {
            valueToWrite.add(null);
        }

    } catch (Exception e) {
        valueToWrite.add(null);
        valueToWrite.add(null);
    }

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    Date date = status.getCreatedAt();
    valueToWrite.add(dateFormat.format(date)); // element: date
    valueToWrite.add(getDateCrawler()); // element: datecrawler
    valueToWrite.add(status.getInReplyToScreenName()); // element: replyto

    String tooltip = "";
    try {

        String geoname = status.getPlace().getName();
        if (geoname != null) {
            tooltip = "user = " + name + ", geoname = " + geoname;
        }

    } catch (Exception e) {
        tooltip = "";
    }
    valueToWrite.add(tooltip.trim()); // element: tooltip
    valueToWrite.add(SOURCE); // element: source

    return valueToWrite;
}

From source file:tweetcrawling.TweetCrawler.java

public void printTweets(String csvOut) throws IOException, TwitterException {

    for (Status status : getStatuses()) {

        // Getting the value to be written

        Long tid = status.getId();
        String tweetid = tid.toString();

        ArrayList<String> valueToWrite = new ArrayList<String>();

        User user = status.getUser();
        String screenname = user.getScreenName();
        String name = user.getName();
        String url = getTweetUrl(screenname, tweetid);

        valueToWrite.add(url); // element: id
        valueToWrite.add(screenname); // element: userid
        valueToWrite.add(name); // element: user

        // element: gender
        if (name != null && !name.isEmpty()) {
            valueToWrite.add(getUserGender(name));
        } else if (screenname != null && !screenname.isEmpty()) {
            valueToWrite.add(getUserGender(screenname));
        } else {//  w w w.ja  v  a  2  s .  c  om
            valueToWrite.add("");
        }

        valueToWrite.add(user.getLocation()); // element: location
        valueToWrite.add("" + user.getFollowersCount()); // element: followercount
        valueToWrite.add("" + user.getFriendsCount()); // element: friendscount
        valueToWrite.add("" + user.getStatusesCount()); // element: statuscount

        try {
            List<String> coor = new ArrayList<String>();
            String latitude = "" + status.getGeoLocation().getLatitude();
            String longitude = "" + status.getGeoLocation().getLongitude();
            coor.add(latitude);
            coor.add(longitude);

            if (coor != null && !coor.isEmpty() && coor.size() > 0) {
                valueToWrite.add(coor.get(0)); // element: latitude
                valueToWrite.add(coor.get(1)); // element: longitude
                valueToWrite.add(coor.get(0) + "," + coor.get(1));
            } else {
                valueToWrite.add(null);
                valueToWrite.add(null);
                valueToWrite.add(null);
            }
        } catch (Exception e) {
            valueToWrite.add(null);
            valueToWrite.add(null);
            valueToWrite.add(null);
        }

        try {

            String geoname = status.getPlace().getName();
            String country = status.getPlace().getCountry();

            if (geoname != null) {
                valueToWrite.add(geoname);
            } else {
                valueToWrite.add(null);
            }

            if (country != null) {
                valueToWrite.add(country);
            } else {
                valueToWrite.add(null);
            }

        } catch (Exception e) {
            valueToWrite.add(null);
            valueToWrite.add(null);
        }

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        Date date = status.getCreatedAt();
        valueToWrite.add(dateFormat.format(date)); // element: date
        valueToWrite.add(getDateCrawler()); // element: datecrawler
        valueToWrite.add(status.getText()); // element: body
        valueToWrite.add(status.getInReplyToScreenName()); // element: replyto

        String tooltip = "";
        try {

            String geoname = status.getPlace().getName();
            if (geoname != null) {
                tooltip = "user = " + name + ", geoname = " + geoname;
            }

        } catch (Exception e) {
            tooltip = "";
        }
        valueToWrite.add(tooltip.trim()); // element: tooltip
        valueToWrite.add(SOURCE); // element: source

        // Write valueToWrite to csv external file

        FileWriter fw = new FileWriter(csvOut, true);
        PrintWriter pw = new PrintWriter(fw);

        String content = "'";

        for (int i = 0; i < valueToWrite.size() - 1; i++) {
            content += valueToWrite.get(i) + "','";
        }

        content += valueToWrite.get(valueToWrite.size()) + "'";

        pw.print(content);

        pw.flush();
        pw.close();
        fw.close();

    }
}

From source file:twitbak.TwitBak.java

License:Open Source License

/**
 * Returns a JSONObject containing user data.
 * @param user/*ww  w  .  jav 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.metrics.TwitterMetrics.java

/**
 * @param args the command line arguments
 *///from w  w  w.  j  a v  a  2s .  c om
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:TwitterLookUpUsers.LookupUsers.java

License:Apache License

public static void main(String[] args) throws InterruptedException {

    Postgresql.DBBaglan();/*ww  w .j  a  v a 2  s . 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:twittynumnum.FutureListener.java

public void listen(String[] keywords) {

    StatusListener listener = new StatusListener() {
        @Override/*  w  w w  .  j  av a2  s  . c  om*/
        public void onException(Exception arg0) {

        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice arg0) {

        }

        @Override
        public void onScrubGeo(long arg0, long arg1) {

        }

        @Override
        public void onStatus(Status status) {
            User user = status.getUser();
            String username = user.getScreenName();
            String profileLocation = user.getLocation();
            long tweetId = status.getId();
            String content = status.getText();
            Date tweetDate = status.getCreatedAt();
            out.print(tweetId + "\t" + tweetDate + "\t" + username + "\t" + profileLocation + "\t"
                    + content.replaceAll("\n", "/n") + "\n");
        }

        @Override
        public void onTrackLimitationNotice(int arg0) {

        }

        @Override
        public void onStallWarning(StallWarning sw) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

    };

    FilterQuery filter = new FilterQuery();

    filter.track(keywords);
    twitterStream.addListener(listener);
    twitterStream.filter(filter);
}

From source file:uk.ac.susx.tag.method51.twitter.Tweet.java

License:Apache License

public Tweet(Status status) {
    this();/*w  ww .ja  va  2s.  c o 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);
    }
}