Example usage for twitter4j User getProfileImageURL

List of usage examples for twitter4j User getProfileImageURL

Introduction

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

Prototype

String getProfileImageURL();

Source Link

Document

Returns the profile image url of the user

Usage

From source file:twitter.crawler.TwitterCrawler.java

public static void main(String[] args) {
    try {//from   w  ww  .  j  a v a  2 s .  co  m
        // 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);
    }
}

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  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

/**
 * Retorna la URL de la imagen de usuario.
 * @return/*w w  w  .  java 2s. c o  m*/
 * @throws IllegalStateException
 * @throws TwitterException
 */
public String darImagenUsuario() throws IllegalStateException, TwitterException {
    String ruta = "";
    User user1 = null;
    user1 = user.showUser(user.getId());
    ruta = user1.getProfileImageURL().toString();
    return ruta;
}

From source file:User.SearchUsers.java

License:Apache License

public String[] getResults(String name) {
    try {//from  ww w . ja  v a 2s . c  o  m
        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;
}

From source file:Utils.ConvertUsers.java

License:Open Source License

public Set<TwitterUser> convertAll(Set<User> users) {

    Set<TwitterUser> twitterUsers = new HashSet();
    TwitterUser twitterUser;//ww w. j av a  2 s  .  c o m

    for (User user : users) {
        twitterUser = new TwitterUser();
        twitterUser.setCreated_at(user.getCreatedAt());
        twitterUser.setDescription(user.getDescription());
        twitterUser.setFollowers_count(user.getFollowersCount());
        twitterUser.setLang(user.getLang());
        twitterUser.setLocation(user.getLocation());
        twitterUser.setName(user.getName());
        twitterUser.setProfile_image_url(user.getProfileImageURL());
        twitterUser.setScreen_name(user.getScreenName());
        twitterUser.setIdTwitter(user.getId());
        twitterUser.setFriends_count(user.getFriendsCount());
        twitterUser.setProfile_banner_url(user.getProfileBannerURL());
        twitterUsers.add(twitterUser);
    }
    return twitterUsers;
}

From source file:Utils.ConvertUsers.java

License:Open Source License

public TwitterUser convertOne(User user) {

    TwitterUser twitterUser;/* w w  w . ja va 2  s  .  c  o  m*/

    twitterUser = new TwitterUser();
    twitterUser.setCreated_at(user.getCreatedAt());
    twitterUser.setDescription(user.getDescription());
    twitterUser.setFollowers_count(user.getFollowersCount());
    twitterUser.setLang(user.getLang());
    twitterUser.setLocation(user.getLocation());
    twitterUser.setName(user.getName());
    twitterUser.setProfile_image_url(user.getProfileImageURL());
    twitterUser.setScreen_name(user.getScreenName());
    twitterUser.setIdTwitter(user.getId());
    twitterUser.setFriends_count(user.getFriendsCount());
    twitterUser.setProfile_banner_url(user.getProfileBannerURL());

    return twitterUser;
}