List of usage examples for twitter4j User getId
long getId();
From source file:de.vanita5.twittnuker.task.CacheUsersStatusesTask.java
License:Open Source License
@Override protected Void doInBackground(final Void... args) { if (all_statuses == null || all_statuses.length == 0) return null; final Extractor extractor = new Extractor(); final Set<ContentValues> cachedUsersValues = new HashSet<ContentValues>(); final Set<ContentValues> cached_statuses_values = new HashSet<ContentValues>(); final Set<ContentValues> hashtag_values = new HashSet<ContentValues>(); final Set<Long> userIds = new HashSet<Long>(); final Set<Long> status_ids = new HashSet<Long>(); final Set<String> hashtags = new HashSet<String>(); final Set<User> users = new HashSet<User>(); for (final TwitterListResponse<twitter4j.Status> values : all_statuses) { if (values == null || values.list == null) { continue; }/*from ww w. ja v a 2 s.co m*/ final List<twitter4j.Status> list = values.list; for (final twitter4j.Status status : list) { if (status == null || status.getId() <= 0) { continue; } status_ids.add(status.getId()); cached_statuses_values.add(makeStatusContentValues(status, values.account_id)); hashtags.addAll(extractor.extractHashtags(status.getText())); final User user = status.getUser(); if (user != null && user.getId() > 0) { users.add(user); final ContentValues filtered_users_values = new ContentValues(); filtered_users_values.put(Filters.Users.NAME, user.getName()); filtered_users_values.put(Filters.Users.SCREEN_NAME, user.getScreenName()); final String filtered_users_where = Where.equals(Filters.Users.USER_ID, user.getId()).getSQL(); resolver.update(Filters.Users.CONTENT_URI, filtered_users_values, filtered_users_where, null); } } } bulkDelete(resolver, CachedStatuses.CONTENT_URI, CachedStatuses.STATUS_ID, status_ids, null, false); bulkInsert(resolver, CachedStatuses.CONTENT_URI, cached_statuses_values); for (final String hashtag : hashtags) { final ContentValues hashtag_value = new ContentValues(); hashtag_value.put(CachedHashtags.NAME, hashtag); hashtag_values.add(hashtag_value); } bulkDelete(resolver, CachedHashtags.CONTENT_URI, CachedHashtags.NAME, hashtags, null, true); bulkInsert(resolver, CachedHashtags.CONTENT_URI, hashtag_values); for (final User user : users) { userIds.add(user.getId()); cachedUsersValues.add(makeCachedUserContentValues(user)); } bulkDelete(resolver, CachedUsers.CONTENT_URI, CachedUsers.USER_ID, userIds, null, false); bulkInsert(resolver, CachedUsers.CONTENT_URI, cachedUsersValues); return null; }
From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues makeAccountContentValuesBasic(final Configuration conf, final String basicUsername, final String basicPassword, final User user, final int color, final String apiUrlFormat, final boolean noVersionSuffix) { if (user == null || user.getId() <= 0) return null; final ContentValues values = new ContentValues(); if (basicUsername == null || basicPassword == null) return null; values.put(Accounts.BASIC_AUTH_USERNAME, basicUsername); values.put(Accounts.BASIC_AUTH_PASSWORD, basicPassword); values.put(Accounts.AUTH_TYPE, Accounts.AUTH_TYPE_BASIC); values.put(Accounts.ACCOUNT_ID, user.getId()); values.put(Accounts.SCREEN_NAME, user.getScreenName()); values.put(Accounts.NAME, user.getName()); values.put(Accounts.PROFILE_IMAGE_URL, ParseUtils.parseString(user.getProfileImageUrlHttps())); values.put(Accounts.PROFILE_BANNER_URL, ParseUtils.parseString(user.getProfileBannerImageUrl())); values.put(Accounts.COLOR, color);//from w w w . j av a2s. com values.put(Accounts.IS_ACTIVATED, 1); values.put(Accounts.API_URL_FORMAT, apiUrlFormat); values.put(Accounts.NO_VERSION_SUFFIX, noVersionSuffix); return values; }
From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues makeAccountContentValuesOAuth(final Configuration conf, final AccessToken accessToken, final User user, final int authType, final int color, final String apiUrlFormat, final boolean sameOAuthSigningUrl, final boolean noVersionSuffix) { if (user == null || user.getId() <= 0 || accessToken == null || user.getId() != accessToken.getUserId()) return null; final ContentValues values = new ContentValues(); values.put(Accounts.OAUTH_TOKEN, accessToken.getToken()); values.put(Accounts.OAUTH_TOKEN_SECRET, accessToken.getTokenSecret()); values.put(Accounts.CONSUMER_KEY, conf.getOAuthConsumerKey()); values.put(Accounts.CONSUMER_SECRET, conf.getOAuthConsumerSecret()); values.put(Accounts.AUTH_TYPE, authType); values.put(Accounts.ACCOUNT_ID, user.getId()); values.put(Accounts.SCREEN_NAME, user.getScreenName()); values.put(Accounts.NAME, user.getName()); values.put(Accounts.PROFILE_IMAGE_URL, ParseUtils.parseString(user.getProfileImageUrlHttps())); values.put(Accounts.PROFILE_BANNER_URL, ParseUtils.parseString(user.getProfileBannerImageUrl())); values.put(Accounts.COLOR, color);//from w w w . j av a 2 s . c om values.put(Accounts.IS_ACTIVATED, 1); values.put(Accounts.API_URL_FORMAT, apiUrlFormat); values.put(Accounts.SAME_OAUTH_SIGNING_URL, sameOAuthSigningUrl); values.put(Accounts.NO_VERSION_SUFFIX, noVersionSuffix); return values; }
From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues makeAccountContentValuesTWIP(final Configuration conf, final User user, final int color, final String apiUrlFormat, final boolean noVersionSuffix) { if (user == null || user.getId() <= 0) return null; final ContentValues values = new ContentValues(); values.put(Accounts.AUTH_TYPE, Accounts.AUTH_TYPE_TWIP_O_MODE); values.put(Accounts.ACCOUNT_ID, user.getId()); values.put(Accounts.SCREEN_NAME, user.getScreenName()); values.put(Accounts.NAME, user.getName()); values.put(Accounts.PROFILE_IMAGE_URL, ParseUtils.parseString(user.getProfileImageUrlHttps())); values.put(Accounts.PROFILE_BANNER_URL, ParseUtils.parseString(user.getProfileBannerImageUrl())); values.put(Accounts.COLOR, color);/*from www .j a v a 2s.com*/ values.put(Accounts.IS_ACTIVATED, 1); values.put(Accounts.API_URL_FORMAT, apiUrlFormat); values.put(Accounts.NO_VERSION_SUFFIX, noVersionSuffix); return values; }
From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues makeCachedUserContentValues(final User user) { if (user == null || user.getId() <= 0) return null; final String profile_image_url = ParseUtils.parseString(user.getProfileImageUrlHttps()); final String url = ParseUtils.parseString(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.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.LOCATION, user.getLocation()); values.put(CachedUsers.DESCRIPTION_PLAIN, user.getDescription()); values.put(CachedUsers.DESCRIPTION_HTML, Utils.formatUserDescription(user)); values.put(CachedUsers.DESCRIPTION_EXPANDED, Utils.formatExpandedUserDescription(user)); values.put(CachedUsers.URL, url); values.put(CachedUsers.URL_EXPANDED, url != null && urls != null && urls.length > 0 ? ParseUtils.parseString(urls[0].getExpandedURL()) : null);//from w ww .j a v a2 s . com values.put(CachedUsers.PROFILE_BANNER_URL, user.getProfileBannerImageUrl()); return values; }
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 w w w .jav a 2 s . co m*/ 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;// w w w .jav a2 s . c om } 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:demo.UserInfo.java
License:Apache License
public static void main(String[] args) throws IOException, TwitterException { //?//from ww w. j ava 2 s . c om 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.ContactsContainerNode.java
License:Open Source License
/** costruttore della classe {@link ContactsContainerNode} * @param fatherFullKey chiave completa del nodo padre * @param key chiave del nodo attuale//from w w w . j a v a 2 s . c o m * @param father puntatore al nodo genitore * @throws TwitterException**/ public ContactsContainerNode(String fatherFullKey, String key, Node father) throws TwitterException { super(fatherFullKey, key, father); /* richiama il costruttore di AbstractNode */ User user = twitter.showUser(father.getKey()); /* preleva l'utente al quale appartiene la lista */ long id = user.getId(); /* recupera il suo id */ if (key.equals("following")) { /* recuperiamo la lista dei following dell'utente scelto */ IDs ids = twitter.getFriendsIDs(id, -1); contactList = ids.getIDs(); } else if (key.equals("followers")) { /* recuperiamo la lista dei followers dell'utente scelto */ IDs ids = twitter.getFollowersIDs(id, -1); contactList = ids.getIDs(); } else { contactList = null; /* errore nel recupero dei dati */ } }
From source file:edu.cmu.geolocator.coder.utils.JSON2Tweet.java
License:Apache License
public JSONTweet readLine() { String line;/* w w w . j a v a 2s. c o m*/ try { line = br.readLine(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return null; } if (line == null) return null; Status tweet = null; try { // parse json to object type tweet = DataObjectFactory.createStatus(line); } catch (TwitterException e) { System.err.println("error parsing tweet object"); return null; } jsontweet.JSON = line; jsontweet.id = tweet.getId(); jsontweet.source = tweet.getSource(); jsontweet.text = tweet.getText(); jsontweet.createdat = tweet.getCreatedAt(); jsontweet.tweetgeolocation = tweet.getGeoLocation(); User user; if ((user = tweet.getUser()) != null) { jsontweet.userdescription = user.getDescription(); jsontweet.userid = user.getId(); jsontweet.userlanguage = user.getLang(); jsontweet.userlocation = user.getLocation(); jsontweet.username = user.getName(); jsontweet.usertimezone = user.getTimeZone(); jsontweet.usergeoenabled = user.isGeoEnabled(); if (user.getURL() != null) { String url = user.getURL().toString(); jsontweet.userurl = url; String addr = url.substring(7).split("/")[0]; String[] countrysuffix = addr.split("[.]"); String suffix = countrysuffix[countrysuffix.length - 1]; jsontweet.userurlsuffix = suffix; try { InetAddress address = null;//InetAddress.getByName(user.getURL().getHost()); String generate_URL // = // "http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=" = "http://www.geoplugin.net/php.gp?ip=" + address.getHostAddress(); URL data = new URL(generate_URL); URLConnection yc = data.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; String temp = ""; while ((inputLine = in.readLine()) != null) { temp += inputLine + "\n"; } temp = temp.split("s:2:\"")[1].split("\"")[0]; jsontweet.userurllocation = temp; } catch (Exception uhe) { //uhe.printStackTrace(); jsontweet.userurllocation = null; } } } return jsontweet; }