Example usage for twitter4j User getId

List of usage examples for twitter4j User getId

Introduction

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

Prototype

long getId();

Source Link

Document

Returns the id of the user

Usage

From source file:com.dwdesign.tweetings.util.Utils.java

License:Open Source License

public static ContentValues makeAccountContentValues(final int color, final AccessToken access_token,
        final User user, final String rest_base_url, final String oauth_base_url,
        final String signing_rest_base_url, final String signing_oauth_base_url, final String search_base_url,
        final String upload_base_url, final String basic_password, final int auth_type) {
    if (user == null || user.getId() <= 0)
        return null;
    final ContentValues values = new ContentValues();
    switch (auth_type) {
    case Accounts.AUTH_TYPE_TWIP_O_MODE: {
        break;//from w  ww.j  a va 2  s  . c  o m
    }
    case Accounts.AUTH_TYPE_BASIC: {
        if (basic_password == null)
            return null;
        values.put(Accounts.BASIC_AUTH_PASSWORD, basic_password);
        break;
    }
    case Accounts.AUTH_TYPE_OAUTH:
    case Accounts.AUTH_TYPE_XAUTH: {
        if (access_token == null)
            return null;
        if (user.getId() != access_token.getUserId())
            return null;
        values.put(Accounts.OAUTH_TOKEN, access_token.getToken());
        values.put(Accounts.TOKEN_SECRET, access_token.getTokenSecret());
        break;
    }
    }
    values.put(Accounts.AUTH_TYPE, auth_type);
    values.put(Accounts.USER_ID, user.getId());
    values.put(Accounts.USERNAME, user.getScreenName());
    values.put(Accounts.PROFILE_IMAGE_URL, user.getProfileImageURL().toString());
    values.put(Accounts.USER_COLOR, color);
    values.put(Accounts.IS_ACTIVATED, 1);
    values.put(Accounts.REST_BASE_URL, rest_base_url);
    values.put(Accounts.SIGNING_REST_BASE_URL, signing_rest_base_url);
    values.put(Accounts.SEARCH_BASE_URL, search_base_url);
    values.put(Accounts.UPLOAD_BASE_URL, upload_base_url);
    values.put(Accounts.OAUTH_BASE_URL, oauth_base_url);
    values.put(Accounts.SIGNING_OAUTH_BASE_URL, signing_oauth_base_url);
    return values;
}

From source file:com.dwdesign.tweetings.util.Utils.java

License:Open Source License

public static ContentValues makeCachedUserContentValues(final User user) {
    if (user == null || user.getId() <= 0)
        return null;
    final ContentValues values = new ContentValues();
    values.put(CachedUsers.NAME, user.getName());
    values.put(CachedUsers.PROFILE_IMAGE_URL, user.getProfileImageURL().toString());
    values.put(CachedUsers.SCREEN_NAME, user.getScreenName());
    values.put(CachedUsers.USER_ID, user.getId());
    return values;
}

From source file:com.dwdesign.tweetings.util.Utils.java

License:Open Source License

public static ContentValues makeDirectMessageContentValues(final DirectMessage message, final long account_id) {
    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;
    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());
    values.put(DirectMessages.TEXT, message.getText());
    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());
    final URL sender_profile_image_url = sender.getProfileImageURL();
    final URL recipient_profile_image_url = recipient.getProfileImageURL();
    if (sender_profile_image_url != null) {
        values.put(DirectMessages.SENDER_PROFILE_IMAGE_URL, sender_profile_image_url.toString());
    }/*  w ww . j a v  a  2 s .  c o  m*/
    if (recipient_profile_image_url != null) {
        values.put(DirectMessages.RECIPIENT_PROFILE_IMAGE_URL, recipient_profile_image_url.toString());
    }
    return values;
}

From source file:com.dwdesign.tweetings.util.Utils.java

License:Open Source License

public static ContentValues makeStatusContentValues(Status status, final long account_id) {
    if (status == null || status.getId() <= 0)
        return null;
    final ContentValues values = new ContentValues();
    values.put(Statuses.ACCOUNT_ID, account_id);
    values.put(Statuses.STATUS_ID, status.getId());
    final boolean is_retweet = status.isRetweet();
    final Status retweeted_status = is_retweet ? status.getRetweetedStatus() : null;
    if (retweeted_status != null) {
        final User retweet_user = status.getUser();
        values.put(Statuses.RETWEET_ID, retweeted_status.getId());
        values.put(Statuses.RETWEETED_BY_ID, retweet_user.getId());
        values.put(Statuses.RETWEETED_BY_NAME, retweet_user.getName());
        values.put(Statuses.RETWEETED_BY_SCREEN_NAME, retweet_user.getScreenName());
        status = retweeted_status;/*from  w  w w  . j  a va 2  s . c o m*/
    }
    final User user = status.getUser();
    if (user != null) {
        final long user_id = user.getId();
        final String profile_image_url = user.getProfileImageURL().toString();
        final String name = user.getName(), screen_name = user.getScreenName();
        values.put(Statuses.USER_ID, user_id);
        values.put(Statuses.NAME, name);
        values.put(Statuses.SCREEN_NAME, screen_name);
        values.put(Statuses.IS_PROTECTED, user.isProtected() ? 1 : 0);
        values.put(Statuses.IS_VERIFIED, user.isVerified() ? 1 : 0);
        values.put(Statuses.PROFILE_IMAGE_URL, profile_image_url);
    }
    if (status.getCreatedAt() != null) {
        values.put(Statuses.STATUS_TIMESTAMP, status.getCreatedAt().getTime());
    }
    values.put(Statuses.TEXT, formatStatusText(status));
    values.put(Statuses.TEXT_PLAIN, status.getText());
    values.put(Statuses.RETWEET_COUNT, status.getRetweetCount());
    values.put(Statuses.IN_REPLY_TO_SCREEN_NAME, status.getInReplyToScreenName());
    values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId());
    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, is_retweet ? 1 : 0);
    values.put(Statuses.IS_FAVORITE, status.isFavorited() ? 1 : 0);
    return values;
}

From source file:com.eventattend.portal.bl.TwitterBL.java

License:Open Source License

public TwitterDTO checkAlreadyFriend(TwitterDTO twitterDTO) {
    String friendScreenName = null;
    int friendId = 0;
    AccessToken accessToken = (AccessToken) twitterDTO.getAccessToken();
    twitter.setOAuthAccessToken(accessToken);
    friendScreenName = twitterDTO.getUserScreeName();
    try {/*from   w  ww.j  a  va2  s  . co  m*/
        twitterDTO = new TwitterDTO();
        User profile = twitter.showUser(friendScreenName);
        friendId = profile.getId();
        IDs friendsIds = twitter.getFriendsIDs();
        int i = 0;
        if (friendsIds != null) {
            for (int userId : friendsIds.getIDs()) {

                if (userId == friendId) {
                    twitterDTO.setAlreadyFriends(true);
                }
            }
        }

        IDs followersIds = twitter.getFollowersIDs();
        if (followersIds != null) {
            for (int userId : followersIds.getIDs()) {
                i++;
                System.out.println(i + " - " + userId + " Already you are follwoing !");

                fetchProfile(twitter.showUser(userId), twitterDTO);

                if (userId == friendId) {
                    System.out.println(friendId + " Friend is following you !");
                    twitterDTO.setFriendIsFollowing(true);
                }
            }
        }
    } catch (TwitterException e) {
        e.printStackTrace();
    }

    return twitterDTO;
}

From source file:com.freshdigitable.udonroad.module.realm.ConfigStoreRealm.java

License:Apache License

@Override
public void addIgnoringUser(User user) {
    final long userId = user.getId();
    realm.executeTransaction(new Realm.Transaction() {
        @Override//  w  ww  .j  ava2  s  .c  o m
        public void execute(Realm realm) {
            realm.insertOrUpdate(new IgnoringUser(userId));
        }
    });
}

From source file:com.freshdigitable.udonroad.module.realm.ConfigStoreRealm.java

License:Apache License

@Override
public void removeIgnoringUser(User user) {
    final long userId = user.getId();
    realm.executeTransaction(new Realm.Transaction() {
        @Override//ww w  .  ja  v a 2 s.  c  o m
        public void execute(Realm realm) {
            realm.where(IgnoringUser.class).equalTo("id", userId).findAll().deleteAllFromRealm();
        }
    });
}

From source file:com.freshdigitable.udonroad.module.realm.ListedUserIDs.java

License:Apache License

ListedUserIDs(User user, int order) {
    this.order = order;
    this.userId = user.getId();
}

From source file:com.freshdigitable.udonroad.module.realm.StatusCacheRealm.java

License:Apache License

private Collection<User> splitUpsertingUser(Collection<Status> updates) {
    Map<Long, User> res = new LinkedHashMap<>(updates.size());
    for (Status s : updates) {
        final User user = s.getUser();
        res.put(user.getId(), user);
    }/*  w  ww.java 2  s  .  com*/
    return res.values();
}

From source file:com.freshdigitable.udonroad.module.realm.UserCacheRealm.java

License:Apache License

@NonNull
@Override/*www .  j a v  a 2 s  .c om*/
public Realm.Transaction upsertTransaction(final Collection<User> entities) {
    return new Realm.Transaction() {
        @Override
        public void execute(Realm realm) {
            final List<UserRealm> upserts = new ArrayList<>(entities.size());
            for (User u : entities) {
                final UserRealm user = findById(realm, u.getId(), UserRealm.class);
                if (user == null) {
                    upserts.add(new UserRealm(u));
                } else {
                    user.merge(u, realm);
                }
            }
            realm.insertOrUpdate(upserts);
        }
    };
}