List of usage examples for twitter4j Status getMediaEntities
MediaEntity[] getMediaEntities();
From source file:nz.net.speakman.android.dreamintweets.twitterstream.TwitterStreamAdapter.java
License:Apache License
private Spanned getTweetText(Status tweet) { String text = tweet.getText(); for (URLEntity urlEntity : tweet.getURLEntities()) { text = text.replace(urlEntity.getURL(), getClickableUrl(urlEntity)); }/*from w ww . j a v a 2s . c om*/ for (MediaEntity mediaEntity : tweet.getMediaEntities()) { // TODO Optionally load images into stream text = text.replace(mediaEntity.getURL(), getClickableMedia(mediaEntity)); } // for (HashtagEntity hashtagEntity : tweet.getHashtagEntities()) { // // TODO Make clickable // } return Html.fromHtml(text); }
From source file:nz.net.speakman.android.dreamintweets.twitterstream.TwitterStreamAdapter.java
License:Apache License
private void loadImages(TwitterStreamViewHolder holder, Status tweet) { Picasso picasso = Picasso.with(mDream); // Author image picasso.load(tweet.getUser().getBiggerProfileImageURLHttps()).into(holder.authorImage); // Any media? If so, load the first one. MediaEntity[] media = tweet.getMediaEntities(); // Photo is currently only media type; if they add more in future, we (obviously) don't handle that. // https://dev.twitter.com/docs/entities#tweets if (media != null && media.length > 0 && "photo".equals(media[0].getType())) { holder.contentImage.setVisibility(View.VISIBLE); final String mediaUrl = media[0].getMediaURLHttps(); picasso.load(mediaUrl).into(holder.contentImage); holder.contentImage.setTag(mediaUrl); holder.contentImage.setOnClickListener(contentImageRowClickListener); } else {// w ww. j av a 2s . c om holder.contentImage.setVisibility(View.GONE); } }
From source file:org.apache.flume.sink.solr.morphline.TwitterSource.java
License:Apache License
private Record extractRecord(String idPrefix, Schema avroSchema, Status status) { User user = status.getUser();/* w w w . j av a 2 s. c om*/ Record doc = new Record(avroSchema); doc.put("id", idPrefix + status.getId()); doc.put("created_at", formatterTo.format(status.getCreatedAt())); doc.put("retweet_count", status.getRetweetCount()); doc.put("retweeted", status.isRetweet()); doc.put("in_reply_to_user_id", status.getInReplyToUserId()); doc.put("in_reply_to_status_id", status.getInReplyToStatusId()); addString(doc, "source", status.getSource()); addString(doc, "text", status.getText()); MediaEntity[] mediaEntities = status.getMediaEntities(); if (mediaEntities.length > 0) { addString(doc, "media_url_https", mediaEntities[0].getMediaURLHttps()); addString(doc, "expanded_url", mediaEntities[0].getExpandedURL()); } doc.put("user_friends_count", user.getFriendsCount()); doc.put("user_statuses_count", user.getStatusesCount()); doc.put("user_followers_count", user.getFollowersCount()); addString(doc, "user_location", user.getLocation()); addString(doc, "user_description", user.getDescription()); addString(doc, "user_screen_name", user.getScreenName()); addString(doc, "user_name", user.getName()); return doc; }
From source file:org.codice.ddf.catalog.twitter.source.TwitterSource.java
License:Open Source License
private Metacard getMetacard(Status status) { MetacardImpl metacard = new MetacardImpl(); metacard.setSourceId(id);//from w w w. j av a 2 s. co m metacard.setId(String.valueOf(status.getId())); metacard.setTitle(status.getText()); metacard.setMetadata("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<Resource>" + "<name>" + status.getText() + "</name>" + "</Resource>"); metacard.setCreatedDate(status.getCreatedAt()); metacard.setModifiedDate(status.getCreatedAt()); metacard.setEffectiveDate(status.getCreatedAt()); metacard.setPointOfContact(status.getUser().getName()); if (status.getURLEntities() != null && status.getURLEntities().length > 0) { try { metacard.setResourceURI(new URI(status.getURLEntities()[0].getExpandedURL())); } catch (URISyntaxException e) { LOGGER.error("Unable to set resource URI.", e); } } else if (status.getMediaEntities() != null && status.getMediaEntities().length > 0) { try { metacard.setResourceURI(new URI(status.getMediaEntities()[0].getExpandedURL())); } catch (URISyntaxException e) { LOGGER.error("Unable to set resource URI.", e); } } else if (status.getExtendedMediaEntities() != null && status.getExtendedMediaEntities().length > 0) { try { metacard.setResourceURI(new URI(status.getExtendedMediaEntities()[0].getExpandedURL())); } catch (URISyntaxException e) { LOGGER.error("Unable to set resource URI.", e); } } GeoLocation geoLocation = status.getGeoLocation(); if (geoLocation != null) { metacard.setLocation("POINT (" + geoLocation.getLongitude() + " " + geoLocation.getLatitude() + ")"); } return metacard; }
From source file:org.getlantern.firetweet.util.MediaPreviewUtils.java
License:Open Source License
public static String getSupportedFirstLink(final Status status) { if (status == null) return null; final MediaEntity[] mediaEntities = status.getMediaEntities(); if (mediaEntities != null) { for (final MediaEntity mediaEntity : mediaEntities) { final String expanded = mediaEntity.getMediaURLHttps(); if (getSupportedLink(expanded) != null) return expanded; }//from w ww. j a va2 s . c o m } final URLEntity[] urlEntities = status.getURLEntities(); if (urlEntities != null) { for (final URLEntity urlEntity : urlEntities) { final String expanded = urlEntity.getExpandedURL(); if (getSupportedLink(expanded) != null) return expanded; } } return null; }
From source file:org.mariotaku.twidere.extension.streaming.util.MediaPreviewUtils.java
License:Open Source License
public static String getSupportedFirstLink(final Status status) { if (status == null) return null; final MediaEntity[] medias = status.getMediaEntities(); if (medias != null) { for (final MediaEntity entity : medias) { final String expanded = ParseUtils.parseString(entity.getMediaURLHttps()); if (getSupportedLink(expanded) != null) return expanded; }/*from w w w . j a v a 2 s.co m*/ } final URLEntity[] urls = status.getURLEntities(); if (urls != null) { for (final URLEntity entity : urls) { final String expanded = ParseUtils.parseString(entity.getExpandedURL()); if (getSupportedLink(expanded) != null) return expanded; } } return null; }
From source file:org.nsoft.openbus.model.Mensagem.java
License:Open Source License
private static JSONObject createAddtions(Status s) throws JSONException { JSONObject json = new JSONObject(); Vector<String> metions = new Vector<String>(); UserMentionEntity[] in_metions = s.getUserMentionEntities(); if (in_metions != null) { for (UserMentionEntity metion : in_metions) { metions.add(metion.getName()); }//from w w w .ja v a 2 s .c om } URLEntity[] urls = s.getURLEntities(); Vector<String> image_files = new Vector<String>(); MediaEntity[] in_medias = s.getMediaEntities(); if (in_medias != null) { for (MediaEntity media : in_medias) { image_files.add(media.getMediaURL().toString()); } } json.put("metions", metions); json.put("image_files", metions); json.put("inReplyId", s.getInReplyToStatusId()); return json; }
From source file:org.tweetalib.android.model.TwitterMediaEntity.java
License:Apache License
public static TwitterMediaEntity createMediaEntity(Status status) { MediaEntity[] mediaEntities;/*from w w w . j a v a 2 s . c o m*/ URLEntity[] urlEntities; if (status.isRetweet()) { mediaEntities = status.getRetweetedStatus().getMediaEntities(); urlEntities = status.getRetweetedStatus().getURLEntities(); } else { mediaEntities = status.getMediaEntities(); urlEntities = status.getURLEntities(); } if (mediaEntities != null && mediaEntities.length > 0) { return new TwitterMediaEntity(mediaEntities[0]); } else if (urlEntities != null) { for (URLEntity urlEntity : urlEntities) { // This shouldn't be necessary, but is String expandedUrl = urlEntity.getExpandedURL(); if (expandedUrl == null) { continue; } TwitterMediaEntity entity = getTwitterMediaEntityFromUrl(urlEntity.getURL(), urlEntity.getExpandedURL()); if (entity != null) { return entity; } } } return null; }
From source file:org.tweetalib.android.TwitterUtil.java
License:Apache License
public static String getStatusMarkup(Status status) { return getStatusMarkup(status.getText(), status.getMediaEntities(), status.getURLEntities(), showFullUrl); }
From source file:org.wandora.application.tools.extractors.twitter.AbstractTwitterExtractor.java
License:Open Source License
public Topic reifyTweet(Status t, TopicMap tm) { Topic tweetTopic = null;/*from ww w . j a v a 2s . c o m*/ try { long tId = t.getId(); String msg = t.getText(); User user = t.getUser(); if (user == null) { tweetTopic = reifyTweet(tId, null, msg, tm); } else { String userScreenName = user.getScreenName(); tweetTopic = reifyTweet(tId, userScreenName, msg, tm); Topic userTopic = reifyTwitterUser(user, tm); if (tweetTopic != null && userTopic != null) { Association a = tm.createAssociation(getTwitterFromUserType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(userTopic, getTwitterUserType(tm)); } } /* String toUser = t.getToUser(); if(toUser != null) { long toUid = t.getToUserId(); Topic toUserTopic = reifyTwitterUser(toUser, toUid, tm); if(tweetTopic != null && toUserTopic != null) { Association a = tm.createAssociation(getTwitterToUserType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(toUserTopic, getTwitterUserType(tm)); } } */ Date d = t.getCreatedAt(); if (tweetTopic != null && d != null) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateStr = df.format(d); tweetTopic.setData(getTweetDateType(tm), TMBox.getLangTopic(tweetTopic, DEFAULT_LANG), dateStr); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); dateStr = sdf.format(d); Topic dateTopic = ExtractHelper.getOrCreateTopic(DATE_SI_BODY + dateStr, dateStr, getTweetDateType(tm), tm); if (dateTopic != null) { Association a = tm.createAssociation(getTweetDateType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(dateTopic, getTweetDateType(tm)); } } /* String l = t.getIsoLanguageCode(); if(l != null) { Topic tweetLangTopic = TMBox.getLangTopic(tweetTopic, l); if(tweetLangTopic != null) { Association a = tm.createAssociation(getTweetLangType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(tweetLangTopic, getTweetLangType(tm)); } } */ GeoLocation geo = t.getGeoLocation(); if (geo != null) { double lat = geo.getLatitude(); double lon = geo.getLongitude(); String geoLocStr = lat + "," + lon; tweetTopic.setData(getTweetGeoLocationType(tm), TMBox.getLangTopic(tweetTopic, DEFAULT_LANG), geoLocStr); } HashtagEntity[] entities = t.getHashtagEntities(); if (entities != null && entities.length > 0) { for (int i = 0; i < entities.length; i++) { Topic entityTopic = reifyHashtagEntity(entities[i], tm); if (entityTopic != null) { Association a = tm.createAssociation(getHashtagType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(entityTopic, getHashtagType(tm)); } } } MediaEntity[] mediaEntities = t.getMediaEntities(); if (mediaEntities != null && mediaEntities.length > 0) { for (int i = 0; i < mediaEntities.length; i++) { Topic entityTopic = reifyMediaEntity(mediaEntities[i], tm); if (entityTopic != null) { Association a = tm.createAssociation(getMediaEntityType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(entityTopic, getMediaEntityType(tm)); } } } URLEntity[] urlEntities = t.getURLEntities(); if (urlEntities != null && urlEntities.length > 0) { for (int i = 0; i < urlEntities.length; i++) { Topic entityTopic = reifyUrlEntity(urlEntities[i], tm); if (entityTopic != null) { Association a = tm.createAssociation(getURLEntityType(tm)); a.addPlayer(tweetTopic, getTweetType(tm)); a.addPlayer(entityTopic, getURLEntityType(tm)); } } } } catch (Exception e) { log(e); } return tweetTopic; }