List of usage examples for twitter4j Status getUser
User getUser();
From source file:nz.net.speakman.android.dreamintweets.twitterstream.TwitterStreamAdapter.java
License:Apache License
private Spanned getTweetUsername(Status tweet) { User user = tweet.getUser(); return Html.fromHtml(getClickableUrl(getUserUrl(user), "@" + user.getScreenName())); }
From source file:nz.net.speakman.android.dreamintweets.twitterstream.TwitterStreamAdapter.java
License:Apache License
private String getTweetUrl(Status tweet) { return String.format(URL_FORMAT_TWEET_LINK, tweet.getUser().getScreenName(), tweet.getId()); }
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 {//from ww w. j a va2 s . c om holder.contentImage.setVisibility(View.GONE); } }
From source file:org.anc.lapps.datasource.twitter.TwitterDatasource.java
/** * Entry point for a Lappsgrid service./*from w ww .j ava 2s .c om*/ * <p> * Each service on the Lappsgrid will accept {@code org.lappsgrid.serialization.Data} object * and return a {@code Data} object with a {@code org.lappsgrid.serialization.lif.Container} * payload. * <p> * Errors and exceptions that occur during processing should be wrapped in a {@code Data} * object with the discriminator set to http://vocab.lappsgrid.org/ns/error * <p> * See <a href="https://lapp.github.io/org.lappsgrid.serialization/index.html?org/lappsgrid/serialization/Data.html>org.lappsgrid.serialization.Data</a><br /> * See <a href="https://lapp.github.io/org.lappsgrid.serialization/index.html?org/lappsgrid/serialization/lif/Container.html>org.lappsgrid.serialization.lif.Container</a><br /> * * @param input A JSON string representing a Data object * @return A JSON string containing a Data object with a Container payload. */ @Override public String execute(String input) { Data<String> data = Serializer.parse(input, Data.class); String discriminator = data.getDiscriminator(); // Return ERRORS back if (Discriminators.Uri.ERROR.equals(discriminator)) { return input; } // Generate an error if the used discriminator is wrong if (!Discriminators.Uri.GET.equals(discriminator)) { return generateError( "Invalid discriminator.\nExpected " + Discriminators.Uri.GET + "\nFound " + discriminator); } Configuration config = new ConfigurationBuilder().setApplicationOnlyAuthEnabled(true).setDebugEnabled(false) .build(); // Authentication using saved keys Twitter twitter = new TwitterFactory(config).getInstance(); String key = readProperty(KEY_PROPERTY); if (key == null) { return generateError("The Twitter Consumer Key property has not been set."); } String secret = readProperty(SECRET_PROPERTY); if (secret == null) { return generateError("The Twitter Consumer Secret property has not been set."); } twitter.setOAuthConsumer(key, secret); try { twitter.getOAuth2Token(); } catch (TwitterException te) { String errorData = generateError(te.getMessage()); logger.error(errorData); return errorData; } // Get query String from data payload Query query = new Query(data.getPayload()); // Set the type to Popular or Recent if specified // Results will be Mixed by default. if (data.getParameter("type") == "Popular") query.setResultType(Query.POPULAR); if (data.getParameter("type") == "Recent") query.setResultType(Query.RECENT); // Get lang string String langCode = (String) data.getParameter("lang"); // Verify the validity of the language code and add it to the query if it's valid if (validateLangCode(langCode)) query.setLang(langCode); // Get date strings String sinceString = (String) data.getParameter("since"); String untilString = (String) data.getParameter("until"); // Verify the format of the date strings and set the parameters to query if correctly given if (validateDateFormat(untilString)) query.setUntil(untilString); if (validateDateFormat(sinceString)) query.setSince(sinceString); // Get GeoLocation if (data.getParameter("address") != null) { String address = (String) data.getParameter("address"); double radius = (double) data.getParameter("radius"); if (radius <= 0) radius = 10; Query.Unit unit = Query.MILES; if (data.getParameter("unit") == "km") unit = Query.KILOMETERS; GeoLocation geoLocation; try { double[] coordinates = getGeocode(address); geoLocation = new GeoLocation(coordinates[0], coordinates[1]); } catch (Exception e) { String errorData = generateError(e.getMessage()); logger.error(errorData); return errorData; } query.geoCode(geoLocation, radius, String.valueOf(unit)); } // Get the number of tweets from count parameter, and set it to default = 15 if not specified int numberOfTweets; try { numberOfTweets = (int) data.getParameter("count"); } catch (NullPointerException e) { numberOfTweets = 15; } // Generate an ArrayList of the wanted number of tweets, and handle possible errors. // This is meant to avoid the 100 tweet limit set by twitter4j and extract as many tweets as needed ArrayList<Status> allTweets; Data tweetsData = getTweetsByCount(numberOfTweets, query, twitter); String tweetsDataDisc = tweetsData.getDiscriminator(); if (Discriminators.Uri.ERROR.equals(tweetsDataDisc)) return tweetsData.asPrettyJson(); else { allTweets = (ArrayList<Status>) tweetsData.getPayload(); } // Initialize StringBuilder to hold the final string StringBuilder builder = new StringBuilder(); // Append each Status (each tweet) to the initialized builder for (Status status : allTweets) { String single = status.getCreatedAt() + " : " + status.getUser().getScreenName() + " : " + status.getText() + "\n"; builder.append(single); } // Output results Container container = new Container(); container.setText(builder.toString()); Data<Container> output = new Data<>(Discriminators.Uri.LAPPS, container); return output.asPrettyJson(); }
From source file:org.anhonesteffort.ads.twitter.TweetModel.java
License:Open Source License
public TweetModel(Status status) { id = status.getId();//from ww w . ja v a 2 s.c o m timeMs = status.getCreatedAt().getTime(); handle = status.getUser().getScreenName(); accountPic = status.getUser().getProfileImageURLHttps(); text = status.getText(); }
From source file:org.apache.asterix.external.parser.TweetParser.java
License:Apache License
@Override public void parse(IRawRecord<? extends Status> record, DataOutput out) throws HyracksDataException { Status tweet = record.get(); User user = tweet.getUser(); // Tweet user data ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.SCREEN_NAME)]) .setValue(JObjectUtil.getNormalizedString(user.getScreenName())); ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.LANGUAGE)]) .setValue(JObjectUtil.getNormalizedString(user.getLang())); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.FRIENDS_COUNT)]) .setValue(user.getFriendsCount()); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.STATUS_COUNT)]) .setValue(user.getStatusesCount()); ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.NAME)]) .setValue(JObjectUtil.getNormalizedString(user.getName())); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.FOLLOWERS_COUNT)]) .setValue(user.getFollowersCount()); // Tweet data ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.ID)]) .setValue(String.valueOf(tweet.getId())); int userPos = tweetFieldNameMap.get(Tweet.USER); for (int i = 0; i < mutableUserFields.length; i++) { ((AMutableRecord) mutableTweetFields[userPos]).setValueAtPos(i, mutableUserFields[i]); }//from ww w.j a v a 2 s .c o m if (tweet.getGeoLocation() != null) { ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LATITUDE)]) .setValue(tweet.getGeoLocation().getLatitude()); ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LONGITUDE)]) .setValue(tweet.getGeoLocation().getLongitude()); } else { ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LATITUDE)]).setValue(0); ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LONGITUDE)]).setValue(0); } ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.CREATED_AT)]) .setValue(JObjectUtil.getNormalizedString(tweet.getCreatedAt().toString())); ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.MESSAGE)]) .setValue(JObjectUtil.getNormalizedString(tweet.getText())); for (int i = 0; i < mutableTweetFields.length; i++) { mutableRecord.setValueAtPos(i, mutableTweetFields[i]); } recordBuilder.reset(mutableRecord.getType()); recordBuilder.init(); IDataParser.writeRecord(mutableRecord, out, recordBuilder); }
From source file:org.apache.asterix.external.util.TweetProcessor.java
License:Apache License
public AMutableRecord processNextTweet(Status tweet) { User user = tweet.getUser(); // Tweet user data ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.SCREEN_NAME)]) .setValue(JObjectUtil.getNormalizedString(user.getScreenName())); ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.LANGUAGE)]) .setValue(JObjectUtil.getNormalizedString(user.getLang())); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.FRIENDS_COUNT)]) .setValue(user.getFriendsCount()); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.STATUS_COUNT)]) .setValue(user.getStatusesCount()); ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.NAME)]) .setValue(JObjectUtil.getNormalizedString(user.getName())); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.FOLLOWERS_COUNT)]) .setValue(user.getFollowersCount()); // Tweet data ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.ID)]) .setValue(String.valueOf(tweet.getId())); int userPos = tweetFieldNameMap.get(Tweet.USER); for (int i = 0; i < mutableUserFields.length; i++) { ((AMutableRecord) mutableTweetFields[userPos]).setValueAtPos(i, mutableUserFields[i]); }/*w w w . j a v a2s . c om*/ if (tweet.getGeoLocation() != null) { ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LATITUDE)]) .setValue(tweet.getGeoLocation().getLatitude()); ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LONGITUDE)]) .setValue(tweet.getGeoLocation().getLongitude()); } else { ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LATITUDE)]).setValue(0); ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LONGITUDE)]).setValue(0); } ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.CREATED_AT)]) .setValue(JObjectUtil.getNormalizedString(tweet.getCreatedAt().toString())); ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.MESSAGE)]) .setValue(JObjectUtil.getNormalizedString(tweet.getText())); for (int i = 0; i < mutableTweetFields.length; i++) { mutableRecord.setValueAtPos(i, mutableTweetFields[i]); } return mutableRecord; }
From source file:org.apache.blur.demo.twitter.TwitterSearchQueueReader.java
License:Apache License
private RowMutation toRowMutation(Status tweet) { RowMutation rowMutation = new RowMutation(); rowMutation.setRowId(tweet.getUser().getScreenName()); rowMutation.setTable(tableName);/*from w w w . j av a 2 s .c o m*/ rowMutation.setRowMutationType(RowMutationType.UPDATE_ROW); Record record = new Record(); record.setFamily("tweets"); record.setRecordId(tweet.getUser().getScreenName() + "-" + tweet.getId()); record.addToColumns(new Column("message", tweet.getText())); for (UserMentionEntity mention : tweet.getUserMentionEntities()) { record.addToColumns(new Column("mentions", mention.getScreenName())); } for (HashtagEntity tag : tweet.getHashtagEntities()) { record.addToColumns(new Column("hashtags", tag.getText())); } rowMutation.addToRecordMutations(new RecordMutation(RecordMutationType.REPLACE_ENTIRE_RECORD, record)); log.trace(rowMutation); return rowMutation; }
From source file:org.apache.blur.demo.twitter.Whiteboard.java
License:Apache License
/** * @param args//from w w w . ja v a2 s. c om * @throws TwitterException */ public static void main(String[] args) throws TwitterException { Twitter twitter = new TwitterFactory(new ConfigurationBuilder().build()).getInstance(); OAuth2Token token = twitter.getOAuth2Token(); System.out.println(token.getTokenType()); try { Query query = new Query("Apache"); QueryResult result; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); } } while ((query = result.nextQuery()) != null); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); System.exit(-1); } }
From source file:org.apache.camel.component.twitter.util.TwitterConverter.java
License:Apache License
@Converter public static String toString(Status status) throws ParseException { StringBuilder s = new StringBuilder(); s.append(status.getCreatedAt()).append(" (").append(status.getUser().getScreenName()).append(") "); s.append(status.getText());/*w ww. j a va2s .co m*/ return s.toString(); }