List of usage examples for twitter4j Status getInReplyToUserId
long getInReplyToUserId();
From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java
License:Apache License
public static TwitterQueryResultItemAvro mapItem(String queryOwner, String queryName, String queryString, Status status) { TwitterQueryResultItemAvro result = new TwitterQueryResultItemAvro(); if (queryName != null) queryName = queryName.toLowerCase(); if (queryOwner != null) queryOwner = queryOwner.toLowerCase(); result.setQueryName(queryName);//ww w . j a v a 2 s . c om result.setQueryOwner(queryOwner); result.setQuery(queryString); result.setStatusId(status.getId()); result.setText(status.getText()); result.setRelevantQueryTerms(TwitterUtils.relevantQueryTermsFromStatus(queryString, status)); result.setLang(status.getLang()); result.setCreatedAt(status.getCreatedAt().getTime()); User user = status.getUser(); result.setUserId(user.getId()); result.setScreenName(user.getScreenName()); result.setUserLocation(user.getLocation()); result.setUserName(user.getName()); result.setUserDescription(user.getDescription()); result.setUserIsProtected(user.isProtected()); result.setUserFollowersCount(user.getFollowersCount()); result.setUserCreatedAt(user.getCreatedAt().getTime()); result.setUserCreatedAtAsString(DateTimeUtils.getDateAsText(user.getCreatedAt())); result.setCreatedAtAsString(DateTimeUtils.getDateAsText(status.getCreatedAt())); result.setUserFriendsCount(user.getFriendsCount()); result.setUserListedCount(user.getListedCount()); result.setUserStatusesCount(user.getStatusesCount()); result.setUserFavoritesCount(user.getFavouritesCount()); result.setCurrentUserRetweetId(status.getCurrentUserRetweetId()); result.setInReplyToScreenName(status.getInReplyToScreenName()); result.setInReplyToStatusId(status.getInReplyToStatusId()); result.setInReplyToUserId(status.getInReplyToUserId()); if (status.getGeoLocation() != null) { result.setLatitude(status.getGeoLocation().getLatitude()); result.setLongitude(status.getGeoLocation().getLongitude()); } result.setSource(status.getSource()); result.setTrucated(status.isTruncated()); result.setPossiblySensitive(status.isPossiblySensitive()); result.setRetweet(status.getRetweetedStatus() != null); if (result.getRetweet()) { result.setRetweetStatusId(status.getRetweetedStatus().getId()); result.setRetweetedText(status.getRetweetedStatus().getText()); } result.setRetweeted(status.isRetweeted()); result.setRetweetCount(status.getRetweetCount()); result.setRetweetedByMe(status.isRetweetedByMe()); result.setFavoriteCount(status.getFavoriteCount()); result.setFavourited(status.isFavorited()); if (status.getPlace() != null) { result.setPlace(status.getPlace().getFullName()); } Scopes scopesObj = status.getScopes(); if (scopesObj != null) { List scopes = Arrays.asList(scopesObj.getPlaceIds()); result.setScopes(scopes); } return result; }
From source file:crawling.GetUserTimelineByFile.java
License:Apache License
public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.GetUserTimelineByFile UserFile"); System.exit(-1);/* ww w. j a va 2s.c om*/ } userFile = args[0]; try { FileWriter outFileWhole = new FileWriter("CrawlTweets" + ".txt", true); out = new PrintWriter(outFileWhole); // out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } File inFile = new File(userFile); if (!inFile.isFile()) { System.out.println("Parameter is not an existing file"); return; } BufferedReader br = null; try { br = new BufferedReader(new FileReader(userFile)); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // gets Twitter instance with default credentials Twitter twitter = new TwitterFactory().getInstance(); int count = 0; int totalCount = 0; SimpleDateFormat sdf = new SimpleDateFormat("yyyy, MM, dd"); Date start = null; try { start = sdf.parse("2000, 1, 1"); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } List<Status> statuses = null; // String user = "Porter_Anderson"; // user = "pqtad"; // user = "paradunaa6"; // user = "palifarous"; ArrayList<Long> users = new ArrayList<Long>(); String line = null; //Read from the original file and write to the new //unless content matches data to be removed. try { while ((line = br.readLine()) != null) users.add(Long.parseLong(line)); br.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //users.add(584928891L); //users.add(700425265L); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); System.out.println(); System.out.println("----------------------------------------------"); System.out.println("Start at: " + dateFormat.format(date)); Long sinceID = //218903304682471424L; // 2012/06/29 238893053518151680L; // 2012/08/24 Long maxID = 250409135600975873L; // 2012/09/24 //238893053518151680L; // 2012/08/24 // 227659323180974080L; // 2012/07/24 boolean overflow = false; for (Long usr : users) { System.out.println("%" + usr); out.println("%" + usr); out.println("%" + usr); Paging paging = null; count = 0; for (int i = 1; i < 21; i++) { //paging = new Paging(i, 200); paging = new Paging(i, 200, sinceID, maxID); overflow = false; try { // statuses = twitter.getUserTimeline(user, paging); statuses = twitter.getUserTimeline(usr, paging); Thread.currentThread(); try { Thread.sleep(10500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); //System.exit(-1); } if (statuses.isEmpty()) { if (i > 16) overflow = true; break; } for (Status status : statuses) { String record = ""; record += status.getId(); record += "::" + status.getInReplyToStatusId(); record += "::" + status.getInReplyToUserId(); record += "::" + status.getRetweetCount(); if (status.getRetweetedStatus() != null) record += "::" + status.getRetweetedStatus().getId(); else record += "::" + "-1"; //record += "::" + status.isRetweet(); int len = status.getUserMentionEntities().length; if (len > 0) { record += "::"; for (int l = 0; l < len; l++) { UserMentionEntity ent = status.getUserMentionEntities()[l]; record += "," + ent.getId(); } } else record += "::" + "-1"; len = status.getURLEntities().length; if (len > 0) { record += "::"; for (int l = 0; l < len; l++) { URLEntity ent = status.getURLEntities()[l]; record += "," + ent.getURL() + "|" //+ ent.getDisplayURL() + "|" + ent.getExpandedURL(); } } else record += "::" + "-1"; record += "::" + cleanText(status.getText()); record += "::" + // status.getCreatedAt(); (status.getCreatedAt().getTime() - start.getTime()) / 1000; record += "::" + getSource(status.getSource()); //System.out.println(record); out.println(record); } count += statuses.size(); out.flush(); } totalCount += count; out.println("%" + usr + ", " + count + ", " + overflow); System.out.println("%" + usr + ", " + count + ", " + overflow); out.println("------------------------------------------"); } System.out.println("Total status count is " + totalCount); out.println("#" + totalCount); out.close(); date = new Date(); System.out.println(); System.out.println("----------------------------------------------"); System.out.println("End at: " + dateFormat.format(date)); }
From source file:crawling.GetUserTimelineByFileDiff.java
License:Apache License
public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.GetUserTimelineByFile UserFile"); System.exit(-1);/* www. j ava 2 s . c o m*/ } userFile = args[0]; try { FileWriter outFileWhole = new FileWriter("CrawlTweets" + ".txt", true); outWhole = new PrintWriter(outFileWhole); FileWriter outFileInter = new FileWriter("CrawlInter" + ".txt", true); outInter = new PrintWriter(outFileInter); // out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } File inFile = new File(userFile); if (!inFile.isFile()) { System.out.println("Parameter is not an existing file"); return; } BufferedReader br = null; try { br = new BufferedReader(new FileReader(userFile)); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // gets Twitter instance with default credentials Twitter twitter = new TwitterFactory().getInstance(); int count = 0; int countInter = 0; int totalCount = 0; int totalCountInter = 0; SimpleDateFormat sdf = new SimpleDateFormat("yyyy, MM, dd"); Date start = null; try { start = sdf.parse("2000, 1, 1"); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } List<Status> statuses = null; // String user = "Porter_Anderson"; // user = "pqtad"; // user = "paradunaa6"; // user = "palifarous"; // statuses = twitter.getUserTimeline(user); //String usersS = "490495670,210462629,731570426,174646182,381163846,308812526,595154838,47356666,590795627,466854690,560386951,406747522,767819150,193105498,725874775,381257304,486727765,39469575,68239634,187739283,27048882,172979072,16075589,618047540,841958365,707631710,76274554,334451278,573978436,782711790,498017142,764236789,88185343,293950091,726606902,221410697,566098451,32987449,73497385,223182159,571182929,769441794,16225570,404748449,249953519,713693096,727692930,178473099,366957548,255171527,411892240,370333418,753509292,765928471,49389074,422867487,185298515,112841821,524731824,132207254,431289858,35602356,747638244,76398937,276388822,221106768,608597994,532423674,509070257,235773945,263995811,61575477,48606725,518136068,450781132,631504150,842236698,840479664,306291201,59829276,541212815,264436593,262466303,302157661,135587748,399229428,265344815,225280446,540254332,218019401,260453139,187424025,177051847,351065900,406684867,293234971,219356963,280763734,59290083,214750688"; //String[] splits = usersS.split(","); ArrayList<Long> users = new ArrayList<Long>(); String line = null; //Read from the original file and write to the new //unless content matches data to be removed. try { while ((line = br.readLine()) != null) { users.add(Long.parseLong(line)); } br.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //users.add(584928891L); //users.add(700425265L); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); System.out.println(); System.out.println("----------------------------------------------"); System.out.println("Start at: " + dateFormat.format(date)); Long sinceID = //218903304682471424L; // 2012/06/29 238893053518151680L; // 2012/08/24 Long maxID = 250409135600975873L; // 2012/09/24 //238893053518151680L; // 2012/08/24 // 227659323180974080L; // 2012/07/24 boolean overflow = false; for (Long usr : users) { System.out.println("%" + usr); outWhole.println("%" + usr); outInter.println("%" + usr); Paging paging = null; count = 0; countInter = 0; for (int i = 1; i < 21; i++) { //paging = new Paging(i, 200); paging = new Paging(i, 200, sinceID, maxID); overflow = false; try { // statuses = twitter.getUserTimeline(user, paging); statuses = twitter.getUserTimeline(usr, paging); Thread.currentThread(); try { Thread.sleep(10500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); //System.exit(-1); } if (statuses.isEmpty()) { if (i > 16) overflow = true; break; } for (Status status : statuses) { boolean inter = false; //countRT += status.getRetweetCount(); String record = ""; String recordInter = ""; record += status.getId(); // For reply Long replyId = status.getInReplyToStatusId(); if (replyId == -1) record += "::-1::-1"; else { record += "::" + replyId; record += "::" + status.getInReplyToUserId(); inter = true; } // For retweeting Long retweets = (long) status.getRetweetCount(); record += "::" + retweets; if (retweets > 0) { inter = true; if (status.getRetweetedStatus() != null) record += "::" + status.getRetweetedStatus().getId(); else record += "::" + "-1"; // The source of retweeting } //record += "::" + status.isRetweet(); // For mentions int len = status.getUserMentionEntities().length; if (len > 0) { record += "::"; for (int l = 0; l < len; l++) { UserMentionEntity ent = status.getUserMentionEntities()[l]; record += "," + ent.getId(); } inter = true; } else record += "::" + "-1"; recordInter += record; // For URL len = status.getURLEntities().length; if (len > 0) { record += "::"; for (int l = 0; l < len; l++) { URLEntity ent = status.getURLEntities()[l]; record += "," + ent.getURL() + "|" //+ ent.getDisplayURL() + "|" + ent.getExpandedURL(); } } else record += "::" + "-1"; // For text record += "::" + cleanText(status.getText()); // For creating time // record += "::" + status.getCreatedAt().toString(); Long seconds = // status.getCreatedAt(); (status.getCreatedAt().getTime() - start.getTime()) / 1000; record += "::" + seconds; recordInter += "::" + seconds; // For publishing source record += "::" + getSource(status.getSource()); //System.out.println(record); outWhole.println(record); if (inter) { outInter.println(recordInter); countInter++; } } count += statuses.size(); outWhole.flush(); outInter.flush(); } totalCount += count; totalCountInter += countInter; outWhole.println("%" + usr + "," + count + "," + countInter + "," + overflow); outInter.println("%" + usr + "," + count + "," + countInter + "," + overflow); System.out.println("%" + usr + "," + count + "," + countInter + "," + overflow); outWhole.println("------------------------------------------"); outInter.println("------------------------------------------"); } System.out.println("Total status count is " + totalCount + "," + totalCountInter); outWhole.println("#" + totalCount + "," + totalCountInter); outInter.println("#" + totalCount + "," + totalCountInter); outWhole.close(); outInter.close(); date = new Date(); System.out.println(); System.out.println("----------------------------------------------"); System.out.println("End at: " + dateFormat.format(date)); }
From source file:crawling.GetUserTimelineMulti.java
License:Apache License
public void doCrawl() { List<Status> statuses = null; int count = 0; int userIndex = 0; int userTotal = users.size(); boolean overflow = false; for (Long usr : users) { //System.out.println("%" + usr); out.println("%" + usr); Paging paging = null;//from www. j av a 2 s.c o m count = 0; //for (int i = 1; i < 21; i++) { for (int i = 1; i < 4; i++) { paging = new Paging(i, 200); //paging = new Paging(i, 200, sinceId, maxId); overflow = false; try { // statuses = twitter.getUserTimeline(user, paging); statuses = twitters.get(currentCrawl).getUserTimeline(usr, paging); currentCrawl++; if (currentCrawl == this.numCrawl) currentCrawl = 0; /*Thread.currentThread(); try { Thread.sleep(updateFreq); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); //System.exit(-1); } if (statuses == null) { break; } if (statuses.isEmpty()) { if (i > 16) overflow = true; break; } for (Status status : statuses) { int len = status.getUserMentionEntities().length; /* * We only need the interactions */ if (len <= 0) continue; String record = ""; record += status.getId(); record += "::" + status.getInReplyToStatusId(); record += "::" + status.getInReplyToUserId(); record += "::" + status.getRetweetCount(); if (status.getRetweetedStatus() != null) record += "::" + status.getRetweetedStatus().getId(); else record += "::" + "-1"; //record += "::" + status.isRetweet(); //int len = status.getUserMentionEntities().length; if (len > 0) { record += "::"; for (int l = 0; l < len; l++) { UserMentionEntity ent = status.getUserMentionEntities()[l]; record += "," + ent.getId(); } } else { record += "::" + "-1"; } len = status.getURLEntities().length; if (len > 0) { record += "::"; for (int l = 0; l < len; l++) { URLEntity ent = status.getURLEntities()[l]; record += "," + ent.getURL() + "|" //+ ent.getDisplayURL() + "|" + ent.getExpandedURL(); } } else record += "::" + "-1"; //record += "::" + cleanText(status.getText()); // We just ignore the text content in this crawling record += "::-1"; record += "::" + // status.getCreatedAt(); (status.getCreatedAt().getTime() - start.getTime()) / 1000; record += "::" + getSource(status.getSource()); // Geo Location if (status.getGeoLocation() != null) record += "::" + status.getGeoLocation(); else record += "::" + "-1"; //System.out.println(record); out.println(record); count++; } //count += statuses.size(); } out.flush(); totalCount += count; out.println("%" + usr + ", " + count + ", " + overflow); outUserId.println(usr + "," + count); //System.out.println("%" + usr + ", " + count + ", " + overflow); System.out.println(userIndex + "/" + userTotal + ", " + count); //+ ", " + (overflow ? "overflow" : "not overflow")); userIndex++; out.println("------------------------------------------"); } System.out.println("Total status count is " + totalCount); outUserId.println("#" + totalCount); this.closeFile(); }
From source file:crawling.SearchTweetsHashtag.java
License:Apache License
private static void storeATweet(Status status) { int len = status.getUserMentionEntities().length; /*/*from w w w . jav a 2 s . c om*/ * We only need the interactions */ if (len <= 0) return; String record = ""; record += status.getId(); record += "::" + status.getInReplyToStatusId(); record += "::" + status.getInReplyToUserId(); record += "::" + status.getRetweetCount(); if (status.getRetweetedStatus() != null) record += "::" + status.getRetweetedStatus().getId(); else record += "::" + "-1"; //record += "::" + status.isRetweet(); //int len = status.getUserMentionEntities().length; if (len > 0) { record += "::"; for (int l = 0; l < len; l++) { UserMentionEntity ent = status.getUserMentionEntities()[l]; record += "," + ent.getId(); } } else { record += "::" + "-1"; } len = status.getURLEntities().length; if (len > 0) { record += "::"; for (int l = 0; l < len; l++) { URLEntity ent = status.getURLEntities()[l]; record += "," + ent.getURL() + "|" //+ ent.getDisplayURL() + "|" + ent.getExpandedURL(); } } else record += "::" + "-1"; record += "::" + cleanText(status.getText()); // We just ignore the text content in this crawling //record += "::-1"; record += "::" + // status.getCreatedAt(); (status.getCreatedAt().getTime() - start.getTime()) / 1000; record += "::" + getSource(status.getSource()); // Geo Location if (status.getGeoLocation() != null) record += "::" + status.getGeoLocation(); else record += "::" + "-1"; record += "::" + status.getUser().getId() + "::" + status.getUser().getScreenName() + "::" + status.getUser().getName() + "::" + status.getCreatedAt(); //System.out.println(record); out.println(record); out.flush(); count++; }
From source file:de.jetwick.tw.TwitterSearch.java
License:Apache License
public static Twitter4JTweet toTweet(Status st, User user) { if (user == null) throw new IllegalArgumentException("User mustn't be null!"); if (st == null) throw new IllegalArgumentException("Status mustn't be null!"); Twitter4JTweet tw = new Twitter4JTweet(st.getId(), st.getText(), user.getScreenName()); tw.setCreatedAt(st.getCreatedAt());//from ww w. j av a2s . com tw.setFromUser(user.getScreenName()); if (user.getProfileImageURL() != null) tw.setProfileImageUrl(user.getProfileImageURL().toString()); tw.setSource(st.getSource()); tw.setToUser(st.getInReplyToUserId(), st.getInReplyToScreenName()); tw.setInReplyToStatusId(st.getInReplyToStatusId()); if (st.getGeoLocation() != null) { tw.setGeoLocation(st.getGeoLocation()); tw.setLocation(st.getGeoLocation().getLatitude() + ", " + st.getGeoLocation().getLongitude()); } else if (st.getPlace() != null) tw.setLocation(st.getPlace().getCountryCode()); else if (user.getLocation() != null) tw.setLocation(toStandardLocation(user.getLocation())); return tw; }
From source file:de.vanita5.twittnuker.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();/*from w ww. ja va 2 s . c o m*/ timestamp = getTime(orig.getCreatedAt()); is_retweet = orig.isRetweet(); final Status retweeted = orig.getRetweetedStatus(); final User retweet_user = retweeted != null ? orig.getUser() : null; retweet_id = retweeted != null ? retweeted.getId() : -1; //NOTE getTime(orig.getCreatedAt()) 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 ? ParseUtils.parseString(retweet_user.getProfileImageUrlHttps()) : null; final Status status = retweeted != null ? retweeted : orig; final User user = status.getUser(); user_id = user.getId(); user_name = user.getName(); user_screen_name = user.getScreenName(); user_profile_image_url = ParseUtils.parseString(user.getProfileImageUrlHttps()); user_is_protected = user.isProtected(); user_is_verified = user.isVerified(); user_is_following = user.isFollowing(); text_html = 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 = 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 = new ParcelableLocation(status.getGeoLocation()); is_favorite = status.isFavorited(); text_unescaped = toPlainText(text_html); my_retweet_id = retweeted_by_id == account_id ? id : -1; is_possibly_sensitive = status.isPossiblySensitive(); mentions = ParcelableUserMention.fromUserMentionEntities(status.getUserMentionEntities()); first_media = media != null && media.length > 0 ? media[0].url : null; }
From source file:de.vanita5.twittnuker.service.BackgroundOperationService.java
License:Open Source License
private List<SingleResponse<ParcelableStatus>> updateStatus(final Builder builder, final ParcelableStatusUpdate statusUpdate) { final ArrayList<ContentValues> hashtag_values = new ArrayList<ContentValues>(); final Collection<String> hashtags = extractor.extractHashtags(statusUpdate.text); for (final String hashtag : hashtags) { final ContentValues values = new ContentValues(); values.put(CachedHashtags.NAME, hashtag); hashtag_values.add(values);/* w w w . j av a 2 s.c o m*/ } boolean notReplyToOther = false; mResolver.bulkInsert(CachedHashtags.CONTENT_URI, hashtag_values.toArray(new ContentValues[hashtag_values.size()])); final List<SingleResponse<ParcelableStatus>> results = new ArrayList<SingleResponse<ParcelableStatus>>(); if (statusUpdate.accounts.length == 0) return Collections.emptyList(); try { final boolean hasMedia = statusUpdate.medias != null && statusUpdate.medias.length > 0; final String imagePath = hasMedia ? getImagePathFromUri(this, Uri.parse(statusUpdate.medias[0].uri)) : null; final File imageFile = imagePath != null ? new File(imagePath) : null; String uploadResultUrl = null; if (mUseUploader && imageFile != null && imageFile.exists()) { uploadResultUrl = uploadMedia(imageFile, statusUpdate.accounts, statusUpdate.text); } final String unshortenedContent = mUseUploader && uploadResultUrl != null ? getImageUploadStatus(new String[] { uploadResultUrl.toString() }, statusUpdate.text) : statusUpdate.text; final boolean shouldShorten = mValidator.getTweetLength(unshortenedContent) > mValidator .getMaxTweetLength(); Map<Long, ShortenedStatusModel> shortenedStatuses = null; if (shouldShorten && mUseShortener) { if (mShortener.equals(SERVICE_SHORTENER_HOTOTIN)) { shortenedStatuses = postHototIn(statusUpdate); if (shortenedStatuses == null) throw new ShortenException(this); } else if (mShortener.equals(SERVICE_SHORTENER_TWITLONGER)) { shortenedStatuses = postTwitlonger(statusUpdate); if (shortenedStatuses == null) throw new ShortenException(this); } else { throw new IllegalArgumentException("BackgroundOperationService.java#updateStatus()"); } } if (shouldShorten) { if (!mUseShortener) throw new StatusTooLongException(this); else if (unshortenedContent == null) throw new ShortenException(this); } if (!mUseUploader && statusUpdate.medias != null) { for (final ParcelableMediaUpdate media : statusUpdate.medias) { final String path = getImagePathFromUri(this, Uri.parse(media.uri)); final File file = path != null ? new File(path) : null; if (file != null && file.exists()) { Utils.downscaleImageIfNeeded(file, 95); } } } for (final Account account : statusUpdate.accounts) { String shortenedContent = ""; ShortenedStatusModel shortenedStatusModel = null; final Twitter twitter = getTwitterInstance(this, account.account_id, true, true); if (shouldShorten && mUseShortener && shortenedStatuses != null) { shortenedStatusModel = shortenedStatuses.get(account.account_id); shortenedContent = shortenedStatusModel.getText(); } final StatusUpdate status = new StatusUpdate( shouldShorten && mUseShortener ? shortenedContent : unshortenedContent); status.setInReplyToStatusId(statusUpdate.in_reply_to_status_id); if (statusUpdate.location != null) { status.setLocation(ParcelableLocation.toGeoLocation(statusUpdate.location)); } if (!mUseUploader && hasMedia) { final BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; final long[] mediaIds = new long[statusUpdate.medias.length]; try { for (int i = 0, j = mediaIds.length; i < j; i++) { final ParcelableMediaUpdate media = statusUpdate.medias[i]; final String path = getImagePathFromUri(this, Uri.parse(media.uri)); if (path == null) throw new FileNotFoundException(); BitmapFactory.decodeFile(path, o); final File file = new File(path); final ContentLengthInputStream is = new ContentLengthInputStream(file); is.setReadListener(new StatusMediaUploadListener(this, mNotificationManager, builder, statusUpdate)); final MediaUploadResponse uploadResp = twitter.uploadMedia(file.getName(), is, o.outMimeType); mediaIds[i] = uploadResp.getId(); } } catch (final FileNotFoundException e) { } catch (final TwitterException e) { final SingleResponse<ParcelableStatus> response = SingleResponse.getInstance(e); results.add(response); continue; } status.mediaIds(mediaIds); } status.setPossiblySensitive(statusUpdate.is_possibly_sensitive); if (twitter == null) { results.add(new SingleResponse<ParcelableStatus>(null, new NullPointerException())); continue; } try { final Status twitter_result = twitter.updateStatus(status); //Update Twitlonger statuses if (shouldShorten && mUseShortener && mShortener.equals(SERVICE_SHORTENER_TWITLONGER)) { TweetShortenerUtils.updateTwitlonger(shortenedStatusModel, twitter_result.getId(), twitter); } if (!notReplyToOther) { final long inReplyToUserId = twitter_result.getInReplyToUserId(); if (inReplyToUserId <= 0) { notReplyToOther = true; } } final ParcelableStatus result = new ParcelableStatus(twitter_result, account.account_id, false); results.add(new SingleResponse<ParcelableStatus>(result, null)); } catch (final TwitterException e) { final SingleResponse<ParcelableStatus> response = SingleResponse.getInstance(e); results.add(response); } } } catch (final UpdateStatusException e) { final SingleResponse<ParcelableStatus> response = SingleResponse.getInstance(e); results.add(response); } return results; }
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 w w w. j av a 2s . 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:de.vanita5.twittnuker.util.TwitterContentUtils.java
License:Open Source License
@NonNull public static String getInReplyToName(@NonNull final Status status) { final Status orig = status.isRetweet() ? status.getRetweetedStatus() : status; final long inReplyToUserId = status.getInReplyToUserId(); final UserMentionEntity[] entities = status.getUserMentionEntities(); if (entities == null) return orig.getInReplyToScreenName(); for (final UserMentionEntity entity : entities) { if (inReplyToUserId == entity.getId()) return entity.getName(); }/*from www. j ava2 s. c om*/ return orig.getInReplyToScreenName(); }