Example usage for twitter4j User getCreatedAt

List of usage examples for twitter4j User getCreatedAt

Introduction

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

Prototype

Date getCreatedAt();

Source Link

Usage

From source file:org.mariotaku.twidere.util.ContentValuesCreator.java

License:Open Source License

public static ContentValues createCachedUser(final User user) {
    if (user == null || user.getId() <= 0)
        return null;
    final String profile_image_url = user.getProfileImageUrlHttps();
    final String url = user.getURL();
    final URLEntity[] urls = user.getURLEntities();
    final ContentValues values = new ContentValues();
    values.put(CachedUsers.USER_ID, user.getId());
    values.put(CachedUsers.NAME, user.getName());
    values.put(CachedUsers.SCREEN_NAME, user.getScreenName());
    values.put(CachedUsers.PROFILE_IMAGE_URL, profile_image_url);
    values.put(CachedUsers.PROFILE_BANNER_URL, user.getProfileBannerImageUrl());
    values.put(CachedUsers.CREATED_AT, user.getCreatedAt().getTime());
    values.put(CachedUsers.IS_PROTECTED, user.isProtected());
    values.put(CachedUsers.IS_VERIFIED, user.isVerified());
    values.put(CachedUsers.IS_FOLLOWING, user.isFollowing());
    values.put(CachedUsers.FAVORITES_COUNT, user.getFavouritesCount());
    values.put(CachedUsers.FOLLOWERS_COUNT, user.getFollowersCount());
    values.put(CachedUsers.FRIENDS_COUNT, user.getFriendsCount());
    values.put(CachedUsers.STATUSES_COUNT, user.getStatusesCount());
    values.put(CachedUsers.LISTED_COUNT, user.getListedCount());
    values.put(CachedUsers.MEDIA_COUNT, user.getMediaCount());
    values.put(CachedUsers.LOCATION, user.getLocation());
    values.put(CachedUsers.DESCRIPTION_PLAIN, user.getDescription());
    values.put(CachedUsers.DESCRIPTION_HTML, TwitterContentUtils.formatUserDescription(user));
    values.put(CachedUsers.DESCRIPTION_EXPANDED, TwitterContentUtils.formatExpandedUserDescription(user));
    values.put(CachedUsers.URL, url);
    if (url != null && urls != null && urls.length > 0) {
        values.put(CachedUsers.URL_EXPANDED, urls[0].getExpandedURL());
    }/*  www  . j  a  v  a  2 s  . c  om*/
    values.put(CachedUsers.BACKGROUND_COLOR, ParseUtils.parseColor("#" + user.getProfileBackgroundColor(), 0));
    values.put(CachedUsers.LINK_COLOR, ParseUtils.parseColor("#" + user.getProfileLinkColor(), 0));
    values.put(CachedUsers.TEXT_COLOR, ParseUtils.parseColor("#" + user.getProfileTextColor(), 0));
    return values;
}

From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java

License:Open Source License

/**
 * Looks up the person for this twitter user in the given dataSet and
 * returns it. If it does not already exist, the person will be created and
 * returned./*from ww w .j  a  v  a2s.c  o  m*/
 * 
 * @param user
 * @return
 */
private Person createPersonFromTwitterUser(User user) {

    if (user == null) {
        return null;
    }

    Person person = getPersonForTwitterUser(user);

    String personIdent = createPersonIdentForTwitterUser(user);

    if (person == null) {
        // not previously created
        person = factory.createPerson();

        // set name
        person.setName(user.getName());

        // and add the person to the data set
        person = (Person) this.add(person, personIdent);
    }

    if (person == null) {
        // person could not be created
        return null;
    }

    // tag person
    person.metaTag(TwitterTags.TWITTER);

    // add web account
    String screenName = user.getScreenName();

    if (screenName != null && !screenName.equals("")) {
        // TODO check for existing web account
        WebAccount webAccount = factory.createWebAccount();
        webAccount.setUsername(screenName);
        webAccount.setCreated(user.getCreatedAt());

        webAccount = (WebAccount) this.add(webAccount, screenName);

        if (webAccount != null) {
            webAccount.metaTag(TwitterTags.TWITTER);
            person.extend(webAccount);
        }
    }

    // add location
    String twitterLocation = user.getLocation();

    if (twitterLocation != null && !twitterLocation.equals("")) {
        Location location = factory.createLocation();
        location.setStringValue(twitterLocation);

        location = (Location) this.add(location, "uloc_" + user.getId());

        if (location != null) {
            location.metaTag(TwitterTags.TWITTER);
            person.extend(location);
        }
    }

    // add website
    String twitterWebsite = user.getURL();

    if (twitterWebsite != null) {
        WebSite website = factory.createWebSite();
        website.setAdress(twitterWebsite.toString());

        website = (WebSite) this.add(website);

        if (website != null) {
            website.metaTag(TwitterTags.TWITTER);
            person.extend(website);
        }
    }

    // add profile image
    String profileImageUrl = user.getBiggerProfileImageURL();

    // add original res version if available
    if (screenName != null
            && source.isPropertyTrueElseDefault(TwitterProperties.LOAD_HIGHER_RES_PROFILE_IMAGE_PROPERTY,
                    TwitterProperties.LOAD_HIGHER_RES_PROFILE_IMAGE_DEFAULT)) {
        if (user.getOriginalProfileImageURL() != null) {
            profileImageUrl = user.getOriginalProfileImageURL();
        }
    }

    if (profileImageUrl != null) {
        // create image
        Image profileImage = person.attachImage(profileImageUrl);
        profileImage.tag(TwitterTags.TWITTER);
        profileImage.tag(TwitterTags.PROFILE_IMAGE);
    }

    // add latest status of user
    Status status = user.getStatus();
    if (status != null && source.isPropertyTrue(TwitterProperties.ADD_STATUS_OF_PEOPLE_PROPERTY)) {
        createContentFromTweet(person, status);
    }

    return person;
}

From source file:org.soluvas.buzz.twitter.TwitterUser.java

License:Apache License

/**
 * Clones attributes from Twitter4j's {@link User}.
 * @param src/*from   ww  w .  j a va2 s  .c om*/
 */
public TwitterUser(User src, int revId, DateTime fetchTime) {
    super();
    this.revId = revId;
    this.fetchTime = fetchTime;
    id = src.getId();
    name = src.getName();
    screenName = src.getScreenName();
    location = src.getLocation();
    description = src.getDescription();
    contributorsEnabled = src.isContributorsEnabled();
    profileImageUrl = src.getProfileImageURL();
    biggerProfileImageUrl = src.getBiggerProfileImageURL();
    miniProfileImageUrl = src.getMiniProfileImageURL();
    originalProfileImageUrl = src.getOriginalProfileImageURL();
    profileImageUrlHttps = src.getProfileImageURLHttps();
    biggerProfileImageUrlHttps = src.getBiggerProfileImageURLHttps();
    miniProfileImageUrlHttps = src.getMiniProfileImageURLHttps();
    originalProfileImageUrlHttps = src.getOriginalProfileImageURLHttps();
    url = src.getURL();
    protectedState = src.isProtected();
    followersCount = src.getFollowersCount();
    status = src.getStatus();
    profileBackgroundColor = src.getProfileBackgroundColor();
    profileTextColor = src.getProfileTextColor();
    profileLinkColor = src.getProfileLinkColor();
    profileSidebarFillColor = src.getProfileSidebarFillColor();
    profileSidebarBorderColor = src.getProfileSidebarBorderColor();
    profileUseBackgroundImage = src.isProfileUseBackgroundImage();
    showAllInlineMedia = src.isShowAllInlineMedia();
    friendsCount = src.getFriendsCount();
    createdAt = new DateTime(src.getCreatedAt());
    favouritesCount = src.getFavouritesCount();
    utcOffset = src.getUtcOffset();
    timeZone = src.getTimeZone();
    profileBackgroundImageUrl = src.getProfileBackgroundImageURL();
    profileBackgroundImageUrlHttps = src.getProfileBackgroundImageUrlHttps();
    profileBannerUrl = src.getProfileBannerURL();
    profileBannerRetinaUrl = src.getProfileBannerRetinaURL();
    profileBannerIpadUrl = src.getProfileBannerIPadURL();
    profileBannerIpadRetinaUrl = src.getProfileBannerIPadRetinaURL();
    profileBannerMobileUrl = src.getProfileBannerMobileURL();
    profileBannerMobileRetinaUrl = src.getProfileBannerMobileRetinaURL();
    profileBackgroundTiled = src.isProfileBackgroundTiled();
    lang = src.getLang();
    statusesCount = src.getStatusesCount();
    geoEnabled = src.isGeoEnabled();
    verified = src.isVerified();
    translator = src.isTranslator();
    listedCount = src.getListedCount();
    followRequestSent = src.isFollowRequestSent();
}

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 a  2s .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.  j a  v  a  2s. 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  w  w.  j a va 2s.  c  om*/

        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 w w.  j  av a 2 s . c  o  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:TwitterDownload.TwitterExel.java

public static String writeFollowers(long ID, List<User> followers, String path) {
    try {/*w w w .  j a va  2  s .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:uk.ac.susx.tag.method51.twitter.Tweet.java

License:Apache License

public Tweet(Status status) {
    this();//from   ww  w  .j  a v a  2 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  w w.ja  va2  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());
            }
        }
    };
}