Example usage for twitter4j User getScreenName

List of usage examples for twitter4j User getScreenName

Introduction

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

Prototype

String getScreenName();

Source Link

Document

Returns the screen name of the user

Usage

From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java

License:Open Source License

public static ContentValues makeDirectMessageContentValues(final DirectMessage message, final long account_id,
        final boolean is_outgoing, final boolean large_profile_image) {
    if (message == null || message.getId() <= 0)
        return null;
    final ContentValues values = new ContentValues();
    final User sender = message.getSender(), recipient = message.getRecipient();
    if (sender == null || recipient == null)
        return null;
    final String sender_profile_image_url = ParseUtils.parseString(sender.getProfileImageUrlHttps());
    final String recipient_profile_image_url = ParseUtils.parseString(recipient.getProfileImageUrlHttps());
    values.put(DirectMessages.ACCOUNT_ID, account_id);
    values.put(DirectMessages.MESSAGE_ID, message.getId());
    values.put(DirectMessages.MESSAGE_TIMESTAMP, message.getCreatedAt().getTime());
    values.put(DirectMessages.SENDER_ID, sender.getId());
    values.put(DirectMessages.RECIPIENT_ID, recipient.getId());
    final String text_html = Utils.formatDirectMessageText(message);
    values.put(DirectMessages.TEXT_HTML, text_html);
    values.put(DirectMessages.TEXT_PLAIN, message.getText());
    values.put(DirectMessages.TEXT_UNESCAPED, toPlainText(text_html));
    values.put(DirectMessages.IS_OUTGOING, is_outgoing);
    values.put(DirectMessages.SENDER_NAME, sender.getName());
    values.put(DirectMessages.SENDER_SCREEN_NAME, sender.getScreenName());
    values.put(DirectMessages.RECIPIENT_NAME, recipient.getName());
    values.put(DirectMessages.RECIPIENT_SCREEN_NAME, recipient.getScreenName());
    values.put(DirectMessages.SENDER_PROFILE_IMAGE_URL,
            large_profile_image ? getBiggerTwitterProfileImage(sender_profile_image_url)
                    : sender_profile_image_url);
    values.put(DirectMessages.RECIPIENT_PROFILE_IMAGE_URL,
            large_profile_image ? getBiggerTwitterProfileImage(recipient_profile_image_url)
                    : recipient_profile_image_url);
    final ParcelableMedia[] mediaArray = ParcelableMedia.fromEntities(message);
    if (mediaArray != null) {
        values.put(DirectMessages.MEDIA, JSONSerializer.toJSONArrayString(mediaArray));
        values.put(DirectMessages.FIRST_MEDIA, mediaArray[0].url);
    }//from   ww w  .java  2  s  .c  om
    return values;
}

From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java

License:Open Source License

public static ContentValues makeStatusContentValues(final Status orig, final long accountId,
        final boolean largeProfileImage) {
    if (orig == null || orig.getId() <= 0)
        return null;
    final ContentValues values = new ContentValues();
    values.put(Statuses.ACCOUNT_ID, accountId);
    values.put(Statuses.STATUS_ID, orig.getId());
    values.put(Statuses.STATUS_TIMESTAMP, orig.getCreatedAt().getTime());
    values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet());
    final boolean isRetweet = orig.isRetweet();
    final Status status;
    final Status retweetedStatus = isRetweet ? orig.getRetweetedStatus() : null;
    if (retweetedStatus != null) {
        final User retweetUser = orig.getUser();
        values.put(Statuses.RETWEET_ID, retweetedStatus.getId());
        values.put(Statuses.RETWEET_TIMESTAMP, retweetedStatus.getCreatedAt().getTime());
        values.put(Statuses.RETWEETED_BY_USER_ID, retweetUser.getId());
        values.put(Statuses.RETWEETED_BY_USER_NAME, retweetUser.getName());
        values.put(Statuses.RETWEETED_BY_USER_SCREEN_NAME, retweetUser.getScreenName());
        values.put(Statuses.RETWEETED_BY_USER_PROFILE_IMAGE,
                ParseUtils.parseString(retweetUser.getProfileImageUrlHttps()));
        status = retweetedStatus;/*from   ww  w  .  jav a  2  s  . com*/
    } else {
        status = orig;
    }
    final User user = status.getUser();
    if (user != null) {
        final long userId = user.getId();
        final String profileImageUrl = ParseUtils.parseString(user.getProfileImageUrlHttps());
        final String name = user.getName(), screenName = user.getScreenName();
        values.put(Statuses.USER_ID, userId);
        values.put(Statuses.USER_NAME, name);
        values.put(Statuses.USER_SCREEN_NAME, screenName);
        values.put(Statuses.IS_PROTECTED, user.isProtected());
        values.put(Statuses.IS_VERIFIED, user.isVerified());
        values.put(Statuses.USER_PROFILE_IMAGE_URL,
                largeProfileImage ? getBiggerTwitterProfileImage(profileImageUrl) : profileImageUrl);
        values.put(CachedUsers.IS_FOLLOWING, user.isFollowing());
    }
    final String text_html = Utils.formatStatusText(status);
    values.put(Statuses.TEXT_HTML, text_html);
    values.put(Statuses.TEXT_PLAIN, status.getText());
    values.put(Statuses.TEXT_UNESCAPED, toPlainText(text_html));
    values.put(Statuses.RETWEET_COUNT, status.getRetweetCount());
    values.put(Statuses.REPLY_COUNT, status.getReplyCount());
    values.put(Statuses.DESCENDENT_REPLY_COUNT, status.getDescendentReplyCount());
    values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId());
    values.put(Statuses.IN_REPLY_TO_USER_ID, status.getInReplyToUserId());
    values.put(Statuses.IN_REPLY_TO_USER_NAME, Utils.getInReplyToName(status));
    values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, status.getInReplyToScreenName());
    values.put(Statuses.SOURCE, status.getSource());
    values.put(Statuses.IS_POSSIBLY_SENSITIVE, status.isPossiblySensitive());
    final GeoLocation location = status.getGeoLocation();
    if (location != null) {
        values.put(Statuses.LOCATION, location.getLatitude() + "," + location.getLongitude());
    }
    values.put(Statuses.IS_RETWEET, isRetweet);
    values.put(Statuses.IS_FAVORITE, status.isFavorited());
    final ParcelableMedia[] media = ParcelableMedia.fromEntities(status);
    if (media != null) {
        values.put(Statuses.MEDIA, JSONSerializer.toJSONArrayString(media));
        values.put(Statuses.FIRST_MEDIA, media[0].url);
    }
    final ParcelableUserMention[] mentions = ParcelableUserMention.fromStatus(status);
    if (mentions != null) {
        values.put(Statuses.MENTIONS, JSONSerializer.toJSONArrayString(mentions));
    }
    return values;
}

From source file:de.vanita5.twittnuker.util.Utils.java

License:Open Source License

public static String getUserName(final User user) {
    return getDisplayName(user.getName(), user.getScreenName());
}

From source file:demo.UserFollowers.java

License:Apache License

public static void main(String[] args) throws TwitterException, IOException {
    //?//from  w w  w .ja v  a2 s.c  o  m
    Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
    Twitter tw = new TwitterFactory(configuration).getInstance();
    //String screenName = "masason";
    String screenName = "";
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print(
            "??ScreenName???????!! ex)masason : ");
    screenName = br.readLine();

    //?
    List<Long> followersList = followers(tw, screenName);
    for (int i = 0; i < followersList.size(); i++) {
        //???idscreenName?
        User user = tw.showUser(followersList.get(i));
        System.out.println("[" + (i + 1) + "]" + "ScreenName : " + "[" + user.getScreenName() + "]  "
                + "UserIds : " + followersList.get(i));
    }
}

From source file:demo.UserInfo.java

License:Apache License

public static void main(String[] args) throws IOException, TwitterException {
    //?/* w  w w .j  a  v a2 s  . co  m*/
    Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
    Twitter tw = new TwitterFactory(configuration).getInstance();
    String screenName = "";

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("????ScreenName???????!! ex)masason : ");
    screenName = br.readLine();
    //String screenName = "masason";//masason
    try {
        //?&
        User user = tw.showUser(screenName);
        System.out.println("???");
        System.out.println("User ID : " + user.getId());
        System.out.println("ScreenName : " + user.getScreenName());
        System.out.println("User's Name : " + user.getName());
        System.out.println("Number of Followers : " + user.getFollowersCount());
        System.out.println("Number of Friends : " + user.getFriendsCount());
        System.out.println("Language : " + user.getLang());
        //?
        Status status = user.getStatus();
        System.out.println("???");
        System.out.println("User Created : " + status.getCreatedAt());
        System.out.println("Status ID : " + status.getId());
        System.out.println(status.getSource());
        System.out.println("Tweet" + status.getText());

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:dgsf.twittertree.ContactsContainerIterator.java

License:Open Source License

/** override del metodo next() di Iterator **/
@Override//from   w  w w  . j  a  va 2 s .  c  o m
public Node next() {
    User us;
    try {
        us = this.twitter.showUser(ids[this.index]); /* recupera l'utente da restituire  */
    } catch (TwitterException e) /* errore nel recupero dell'utente */
    {
        this.index++;
        return null;
    }
    this.index++;

    try {
        return new ContactNode(this.fullKey, us.getScreenName(),
                this.root); /* restituisce il contatto dell'utente recuperato */
    } catch (TwitterException e) /* errore nella restituzione del contatto */
    {
        return null;
    }
}

From source file:dgsf.twittertree.ContactsContainerNode.java

License:Open Source License

/** metodo che restituisce l'i-esimo nodo figlio
 * @param index indice relativo all'i-esimo figlio
 * *///from  ww w . j a  va  2 s. c  o m
public Node getSubnode(int index) {
    try {
        /* recupera l'utente figlio con indice numerico index-1 */
        User us = twitter.showUser(contactList[index - 1]);
        return new ContactNode(this.fullKey, us.getScreenName(), this); /* restituisce il nodo del contatto */
    }
    /* recupero fallito */
    catch (IndexOutOfBoundsException e) {
        return null;
    } catch (TwitterException e) {
        return null;
    }
}

From source file:edu.uci.ics.asterix.external.util.TweetProcessor.java

License:Apache License

public AMutableRecord processNextTweet(Status tweet) {
    User user = tweet.getUser();
    ((AMutableString) mutableUserFields[0]).setValue(getNormalizedString(user.getScreenName()));
    ((AMutableString) mutableUserFields[1]).setValue(getNormalizedString(user.getLang()));
    ((AMutableInt32) mutableUserFields[2]).setValue(user.getFriendsCount());
    ((AMutableInt32) mutableUserFields[3]).setValue(user.getStatusesCount());
    ((AMutableString) mutableUserFields[4]).setValue(getNormalizedString(user.getName()));
    ((AMutableInt32) mutableUserFields[5]).setValue(user.getFollowersCount());

    ((AMutableString) mutableTweetFields[0]).setValue(tweet.getId() + "");

    for (int i = 0; i < 6; i++) {
        ((AMutableRecord) mutableTweetFields[1]).setValueAtPos(i, mutableUserFields[i]);
    }//from w ww . j  av a2  s . com
    if (tweet.getGeoLocation() != null) {
        ((AMutableDouble) mutableTweetFields[2]).setValue(tweet.getGeoLocation().getLatitude());
        ((AMutableDouble) mutableTweetFields[3]).setValue(tweet.getGeoLocation().getLongitude());
    } else {
        ((AMutableDouble) mutableTweetFields[2]).setValue(0);
        ((AMutableDouble) mutableTweetFields[3]).setValue(0);
    }
    ((AMutableString) mutableTweetFields[4]).setValue(getNormalizedString(tweet.getCreatedAt().toString()));
    ((AMutableString) mutableTweetFields[5]).setValue(getNormalizedString(tweet.getText()));

    for (int i = 0; i < 6; i++) {
        mutableRecord.setValueAtPos(i, mutableTweetFields[i]);
    }

    return mutableRecord;

}

From source file:edu.ucsc.twitter.PeriodicTweetsSearch.java

License:Apache License

private static String getUserFirstname(long userID) {
    String result = "n/a";
    while (Strings.same(result, "n/a")) {
        try {/*  w ww  .  j  ava2s.c o m*/
            secondBreaker().callStarted();
            try {
                final ResponseList<Status> status = TwitterEnvironment.getTwitterService()
                        .getUserTimeline(userID);
                secondBreaker().callSucceeded();
                if (!status.isEmpty()) {
                    for (Status each : status) {
                        final User user = each.getUser();
                        if (user == null)
                            continue;
                        final String firstname = user.getName();
                        final String screenname = user.getScreenName();
                        final boolean firstNameIsEmpty = Strings.isEmpty(firstname);
                        final boolean screenmaeIsEmpty = Strings.isEmpty(screenname);
                        if (firstNameIsEmpty && screenmaeIsEmpty)
                            return "n/a";
                        if (firstNameIsEmpty && !screenmaeIsEmpty)
                            return dealWithCamelCasing(screenname);
                        if (screenmaeIsEmpty)
                            return dealWithCamelCasing(firstname);
                        return dealWithCamelCasing(firstname);
                    }
                } else {
                    return "none";
                }

            } catch (Exception e) {
                secondBreaker().callFailed(new RuntimeException(e));
                result = "n/a";
            }

        } catch (Exception e) {
            result = "n/a";
        }

    }

    return result;
}

From source file:gohai.simpletweet.SimpleTweet.java

License:Apache License

/**
 *  Send a tweet/*from ww w.j  a  v  a  2 s.c  o  m*/
 *  @param message message to send
 *  @return partial URL of the tweet (e.g. "mrgohai/status/841086396194529280")
 */
public String tweet(String message) {
    try {
        StatusUpdate update = new StatusUpdate(message);
        Status status = twitter.updateStatus(update);

        User user = status.getUser();
        return user.getScreenName() + "/status/" + status.getId();
    } catch (TwitterException e) {
        System.err.println(e.getMessage());
        throw new RuntimeException("Error posting tweet");
    }
}