Example usage for twitter4j User getName

List of usage examples for twitter4j User getName

Introduction

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

Prototype

String getName();

Source Link

Document

Returns the name of the user

Usage

From source file:org.bireme.interop.toJson.Twitter2Json.java

License:Open Source License

private JSONObject getDocument(final Status status) {
    assert status != null;

    final JSONObject obj = new JSONObject();
    final GeoLocation geo = status.getGeoLocation();
    final Place place = status.getPlace();
    final User user = status.getUser();

    obj.put("createdAt", status.getCreatedAt()).put("id", status.getId()).put("lang", status.getLang());
    if (geo != null) {
        obj.put("location_latitude", geo.getLatitude()).put("location_longitude", geo.getLongitude());
    }/*w w w  . j  av  a 2s .  c o m*/
    if (place != null) {
        obj.put("place_country", place.getCountry()).put("place_fullName", place.getFullName())
                .put("place_id", place.getId()).put("place_name", place.getName())
                .put("place_type", place.getPlaceType()).put("place_streetAddress", place.getStreetAddress())
                .put("place_url", place.getURL());
    }
    obj.put("source", status.getSource()).put("text", status.getText());
    if (user != null) {
        obj.put("user_description", user.getDescription()).put("user_id", user.getId())
                .put("user_lang", user.getLang()).put("user_location", user.getLocation())
                .put("user_name", user.getName()).put("user_url", user.getURL());
    }
    obj.put("isTruncated", status.isTruncated()).put("isRetweet", status.isRetweet());

    return obj;
}

From source file:org.botlibre.sense.twitter.Twitter.java

License:Open Source License

public boolean checkFriendship(long friendId, boolean welcomeOnly) throws TwitterException {
    long[] lookup = new long[1];
    lookup[0] = friendId;/* ww w.ja va 2s .c  om*/
    ResponseList<User> users = getConnection().lookupUsers(lookup);
    User friend = users.get(0);
    if (friend.getScreenName().equals(getUserName())) {
        return false;
    }
    if (!getAutoFollowKeywords().isEmpty()) {
        StringWriter writer = new StringWriter();
        writer.write(friend.getScreenName().toLowerCase());
        writer.write(" ");
        writer.write(friend.getDescription().toLowerCase());
        writer.write(" ");
        writer.write(friend.getLocation().toLowerCase());
        writer.write(" ");
        writer.write(friend.getLang().toLowerCase());
        writer.write(" ");
        writer.write(friend.getName().toLowerCase());
        boolean match = false;
        for (String text : getAutoFollowKeywords()) {
            List<String> keywords = new TextStream(text.toLowerCase()).allWords();
            if (new TextStream(writer.toString()).allWords().containsAll(keywords)) {
                match = true;
                break;
            }
        }
        if (!match) {
            log("Autofollow skipping friend, does not match keywords", Level.FINE, friend.getScreenName());
            return false;
        }
    }
    Network memory = getBot().memory().newMemory();
    Vertex speaker = memory.createSpeaker(friend.getScreenName());
    speaker.setPinned(true);
    // Only try to follow a user once.
    if (!speaker.hasRelationship(Primitive.FOLLOWED)) {
        speaker.addRelationship(Primitive.FOLLOWED, memory.createTimestamp());
        memory.save();
        if (!welcomeOnly && getAutoFollow()) {
            log("Adding autofollow friend.", Level.INFO, friend.getScreenName());
            getConnection().createFriendship(friendId);
            Utils.sleep(1000);
        }
        if (!getWelcomeMessage().isEmpty()) {
            log("Sending welcome message.", Level.INFO, friend.getScreenName());
            sendMessage(getWelcomeMessage(), friend.getScreenName());
            Utils.sleep(1000);
        }
        if (welcomeOnly) {
            return false;
        }
        return true;
    }
    log("Autofollow skipping friend, already followed once", Level.FINE, friend.getScreenName());
    return false;
}

From source file:org.celstec.arlearn2.oauth.OauthTwitterWorker.java

License:Open Source License

public String afterSuccesfullAuthentication(HttpServletRequest request) {
    Twitter twitter = new TwitterFactory().getInstance();
    RequestToken token = (RequestToken) request.getSession().getAttribute("requestToken");
    String verifier = request.getParameter("oauth_verifier");
    twitter.setOAuthConsumer(client_id, client_secret);
    try {/*from w ww .jav  a2s.co  m*/
        AccessToken accessToken = twitter.getOAuthAccessToken(token, verifier);
        User user = twitter.verifyCredentials();
        AccountJDO account = AccountManager.addAccount("" + user.getId(), AccountJDO.TWITTERCLIENT, "", "", "",
                user.getName(), user.getProfileImageURL(), false);
        UserLoggedInManager.submitOauthUser(account.getUniqueId(), accessToken.getToken());
        return accessToken.getToken();
    } catch (TwitterException e) {
        log.log(Level.SEVERE, e.getMessage(), e);
    }
    return null;
}

From source file:org.encuestame.social.api.templates.TwitterAPITemplate.java

License:Apache License

@Override
public SocialUserProfile getProfile() throws Exception {
    final SocialUserProfile profile = new SocialUserProfile();
    User user = this.getUser();
    profile.setId(String.valueOf(user.getId()));
    profile.setCreatedAt(user.getCreatedAt());
    profile.setProfileUrl("http://www.twitter.com/" + user.getScreenName());
    profile.setName(user.getName());
    profile.setScreenName(user.getScreenName());
    profile.setUsername(user.getScreenName());
    profile.setProfileImageUrl(user.getProfileImageURL().toString());
    profile.setDescription(user.getDescription());
    profile.setCreatedAt(user.getCreatedAt());
    profile.setLocation(user.getLocation());
    return profile;
}

From source file:org.eventjuggler.services.security.authc.social.twitter.TwitterPrincipal.java

License:Open Source License

public TwitterPrincipal(User user) {
    name = user.getName();
}

From source file:org.gameontext.auth.twitter.TwitterCallback.java

License:Apache License

/**
 * Method that performs introspection on an AUTH string, and returns data as
 * a String->String hashmap./*ww  w  .j a va 2s .c  o m*/
 *
 * @param auth
 *            the authstring to query, as built by an auth impl.
 * @return the data from the introspect, in a map.
 * @throws IOException
 *             if anything goes wrong.
 */
public Map<String, String> introspectAuth(String token, String tokensecret) throws IOException {
    Map<String, String> results = new HashMap<String, String>();

    ConfigurationBuilder c = new ConfigurationBuilder();
    c.setOAuthConsumerKey(key).setOAuthConsumerSecret(secret).setOAuthAccessToken(token)
            .setOAuthAccessTokenSecret(tokensecret).setIncludeEmailEnabled(true).setJSONStoreEnabled(true);

    Twitter twitter = new TwitterFactory(c.build()).getInstance();

    try {
        // ask twitter to verify the token & tokensecret from the auth
        // string
        // if invalid, it'll throw a TwitterException
        User verified = twitter.verifyCredentials();

        // if it's valid, lets grab a little more info about the user.
        String name = verified.getName();
        String email = verified.getEmail();

        results.put("valid", "true");
        results.put("id", "twitter:" + twitter.getId());
        results.put("name", name);
        results.put("email", email);

    } catch (TwitterException e) {
        results.put("valid", "false");
    }

    return results;
}

From source file:org.getlantern.firetweet.model.ParcelableDirectMessage.java

License:Open Source License

public ParcelableDirectMessage(final DirectMessage message, final long account_id, final boolean is_outgoing) {
    this.account_id = account_id;
    this.is_outgoing = is_outgoing;
    final User sender = message.getSender(), recipient = message.getRecipient();
    final String sender_profile_image_url = sender != null ? sender.getProfileImageUrlHttps() : null;
    final String recipient_profile_image_url = recipient != null ? recipient.getProfileImageUrlHttps() : null;
    id = message.getId();//from w  w  w . ja  v a2s. c  om
    timestamp = getTime(message.getCreatedAt());
    sender_id = sender != null ? sender.getId() : -1;
    recipient_id = recipient != null ? recipient.getId() : -1;
    text_html = TwitterContentUtils.formatDirectMessageText(message);
    text_plain = message.getText();
    sender_name = sender != null ? sender.getName() : null;
    recipient_name = recipient != null ? recipient.getName() : null;
    sender_screen_name = sender != null ? sender.getScreenName() : null;
    recipient_screen_name = recipient != null ? recipient.getScreenName() : null;
    this.sender_profile_image_url = sender_profile_image_url;
    this.recipient_profile_image_url = recipient_profile_image_url;
    text_unescaped = toPlainText(text_html);
    media = ParcelableMedia.fromEntities(message);
}

From source file:org.getlantern.firetweet.model.ParcelableStatus.java

License:Open Source License

public ParcelableStatus(final Status orig, final long account_id, final boolean is_gap) {
    this.is_gap = is_gap;
    this.account_id = account_id;
    id = orig.getId();/*w  w w  .  ja  v a 2 s .co m*/
    timestamp = getTime(orig.getCreatedAt());

    final Status retweeted = orig.getRetweetedStatus();
    final User retweet_user = retweeted != null ? orig.getUser() : null;
    is_retweet = orig.isRetweet();
    retweet_id = retweeted != null ? retweeted.getId() : -1;
    retweet_timestamp = retweeted != null ? getTime(retweeted.getCreatedAt()) : -1;
    retweeted_by_id = retweet_user != null ? retweet_user.getId() : -1;
    retweeted_by_name = retweet_user != null ? retweet_user.getName() : null;
    retweeted_by_screen_name = retweet_user != null ? retweet_user.getScreenName() : null;
    retweeted_by_profile_image = retweet_user != null ? retweet_user.getProfileImageUrlHttps() : null;

    final Status quoted = orig.getQuotedStatus();
    final User quote_user = quoted != null ? orig.getUser() : null;
    is_quote = orig.isQuote();
    quote_id = quoted != null ? quoted.getId() : -1;
    quote_text_html = TwitterContentUtils.formatStatusText(orig);
    quote_text_plain = orig.getText();
    quote_text_unescaped = HtmlEscapeHelper.toPlainText(quote_text_html);
    quote_timestamp = orig.getCreatedAt().getTime();
    quote_source = orig.getSource();

    quoted_by_user_id = quote_user != null ? quote_user.getId() : -1;
    quoted_by_user_name = quote_user != null ? quote_user.getName() : null;
    quoted_by_user_screen_name = quote_user != null ? quote_user.getScreenName() : null;
    quoted_by_user_profile_image = quote_user != null ? quote_user.getProfileImageUrlHttps() : null;
    quoted_by_user_is_protected = quote_user != null && quote_user.isProtected();
    quoted_by_user_is_verified = quote_user != null && quote_user.isVerified();

    final Status status;
    if (quoted != null) {
        status = quoted;
    } else if (retweeted != null) {
        status = retweeted;
    } else {
        status = orig;
    }
    final User user = status.getUser();
    user_id = user.getId();
    user_name = user.getName();
    user_screen_name = user.getScreenName();
    user_profile_image_url = user.getProfileImageUrlHttps();
    user_is_protected = user.isProtected();
    user_is_verified = user.isVerified();
    user_is_following = user.isFollowing();
    text_html = TwitterContentUtils.formatStatusText(status);
    media = ParcelableMedia.fromEntities(status);
    text_plain = status.getText();
    retweet_count = status.getRetweetCount();
    favorite_count = status.getFavoriteCount();
    reply_count = status.getReplyCount();
    descendent_reply_count = status.getDescendentReplyCount();
    in_reply_to_name = TwitterContentUtils.getInReplyToName(status);
    in_reply_to_screen_name = status.getInReplyToScreenName();
    in_reply_to_status_id = status.getInReplyToStatusId();
    in_reply_to_user_id = status.getInReplyToUserId();
    source = status.getSource();
    location = ParcelableLocation.fromGeoLocation(status.getGeoLocation());
    is_favorite = status.isFavorited();
    text_unescaped = HtmlEscapeHelper.toPlainText(text_html);
    my_retweet_id = retweeted_by_id == account_id ? id : status.getCurrentUserRetweet();
    is_possibly_sensitive = status.isPossiblySensitive();
    mentions = ParcelableUserMention.fromUserMentionEntities(status.getUserMentionEntities());
    card = ParcelableCardEntity.fromCardEntity(status.getCard(), account_id);
    place_full_name = getPlaceFullName(status.getPlace());
    card_name = card != null ? card.name : null;
}

From source file:org.getlantern.firetweet.model.ParcelableUser.java

License:Open Source License

public ParcelableUser(final User user, final long account_id, final long position) {
    this.position = position;
    this.account_id = account_id;
    final URLEntity[] urls_url_entities = user.getURLEntities();
    id = user.getId();//from w  w  w .  j av a  2  s . co  m
    created_at = user.getCreatedAt().getTime();
    is_protected = user.isProtected();
    is_verified = user.isVerified();
    name = user.getName();
    screen_name = user.getScreenName();
    description_plain = user.getDescription();
    description_html = TwitterContentUtils.formatUserDescription(user);
    description_expanded = TwitterContentUtils.formatExpandedUserDescription(user);
    description_unescaped = HtmlEscapeHelper.toPlainText(description_html);
    location = user.getLocation();
    profile_image_url = user.getProfileImageUrlHttps();
    profile_banner_url = user.getProfileBannerImageUrl();
    url = user.getURL();
    url_expanded = url != null && urls_url_entities != null && urls_url_entities.length > 0
            ? urls_url_entities[0].getExpandedURL()
            : null;
    is_follow_request_sent = user.isFollowRequestSent();
    followers_count = user.getFollowersCount();
    friends_count = user.getFriendsCount();
    statuses_count = user.getStatusesCount();
    favorites_count = user.getFavouritesCount();
    listed_count = user.getListedCount();
    is_following = user.isFollowing();
    background_color = ParseUtils.parseColor("#" + user.getProfileBackgroundColor(), 0);
    link_color = ParseUtils.parseColor("#" + user.getProfileLinkColor(), 0);
    text_color = ParseUtils.parseColor("#" + user.getProfileTextColor(), 0);
    is_cache = false;
    is_basic = false;
}

From source file:org.getlantern.firetweet.model.ParcelableUserList.java

License:Open Source License

public ParcelableUserList(final UserList list, final long account_id, final long position,
        final boolean is_following) {
    final User user = list.getUser();
    this.position = position;
    this.account_id = account_id;
    id = list.getId();//from w  ww .  ja  va2  s.c  om
    is_public = list.isPublic();
    this.is_following = is_following;
    name = list.getName();
    description = list.getDescription();
    user_id = user.getId();
    user_name = user.getName();
    user_screen_name = user.getScreenName();
    user_profile_image_url = user.getProfileImageUrlHttps();
    members_count = list.getMemberCount();
    subscribers_count = list.getSubscriberCount();
}