private static void buscarRelacaoNBANFL(List<Status> listaNBA, List<String> stringsNFL_NBA) { for (Status statusNBA : listaNBA) { if (statusNBA.getText().contains("NFL") || statusNBA.getText().contains("#NFL")) { stringsNFL_NBA.add(statusNBA.getText()); } } }
public static void main(String[] args) throws TwitterException, IOException { Twitter twitter = TwitterFactory.getSingleton(); JLanguageTool langTool = new JLanguageTool(new AmericanEnglish()); List<String> twts = new ArrayList<String>(); for (String arg : args) { Query query = new Query(arg); QueryResult result; int counter = 0; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { if (isEligible(tweet)) { System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); System.out.println(tweet.getLang()); twts.add(tweet.getText()); counter++; } } } while ((query = result.nextQuery()) != null && counter < 5); } for (String str : twts) { List<RuleMatch> matches = langTool.check(str); for (RuleMatch match : matches) { System.out.println( "Potential error at line " + match.getLine() + ", column " + match.getColumn() + ": " + match.getMessage()); System.out.println("Suggested correction: " + match.getSuggestedReplacements()); } } }
public Collection<Tweet> requestTweetsByUser(String otherUser) { List<Tweet> tweets = new ArrayList<Tweet>(); try { // The factory instance is re-useable and thread safe. Twitter twitter = new TwitterFactory().getInstance(); AccessToken accessToken = loadAccessToken(1); twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); twitter.setOAuthAccessToken(accessToken); System.out.println("Fetching latest 100 tweets for [" + otherUser + "]"); // First param of Paging() is the page number, second is the number per page (this is capped // around 200 I think. Paging paging = new Paging(1, 100); List<Status> statuses = twitter.getUserTimeline(otherUser, paging); for (Status status : statuses) { tweets.add( new Tweet( otherUser, status.getText(), (status.getGeoLocation() != null ? status.getGeoLocation().getLatitude() + "," + status.getGeoLocation().getLongitude() : ""))); System.out.println( status.getUser().getName() + "(" + status.getGeoLocation() + "):" + status.getText()); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } return tweets; }
public static void insertTweet(Status tweet) throws SQLException { try { System.out.println(tweet.getCreatedAt() + ": " + tweet.getText()); if (tweet.getRetweetedStatus() != null) { insertRetweet(tweet); return; } PreparedStatement insertTweetStmt = SqlHelper.getInsertTweetStmt(); insertTweetStmt.setLong(1, tweet.getId()); if (tweet.getGeoLocation() != null) { insertTweetStmt.setFloat(2, (float) tweet.getGeoLocation().getLatitude()); insertTweetStmt.setFloat(3, (float) tweet.getGeoLocation().getLongitude()); } else { insertTweetStmt.setFloat(2, 0); insertTweetStmt.setFloat(3, 0); } insertTweetStmt.setString(4, tweet.getText()); insertTweetStmt.setInt(5, (int) tweet.getRetweetCount()); insertTweetStmt.setTimestamp(6, new Timestamp(tweet.getCreatedAt().getTime())); insertTweetStmt.setLong(7, tweet.getInReplyToStatusId()); insertTweetStmt.setLong(8, tweet.getUser().getId()); insertTweetStmt.executeUpdate(); } catch (MySQLIntegrityConstraintViolationException e) { // ignore, this is just a duplicate tweet entry, that's rather normal } }
private ArrayAdapter<String> getTimeline() { SharedPreferences sp = getSharedPreferences("token", MODE_PRIVATE); String token = sp.getString("token", ""); String tokenSecret = sp.getString("token_seacret", ""); // twitterオブジェクトの作成 Twitter tw = new TwitterFactory().getInstance(); // AccessTokenオブジェクトの作成 AccessToken at = new AccessToken(token, tokenSecret); // Consumer keyとConsumer key seacretの設定 tw.setOAuthConsumer("iy2FEHXmSXNReJ6nYQ8FRg", "KYro4jM8BHlLSMsSdTylnTcm3pYaTCiG2UZrYK1yI4"); // AccessTokenオブジェクトを設定 tw.setOAuthAccessToken(at); try { // TLの取得 ResponseList<Status> homeTl = tw.getHomeTimeline(); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1); for (Status status : homeTl) { // つぶやきのユーザーIDの取得 String userName = status.getUser().getScreenName(); // つぶやきの取得 String tweet = status.getText(); adapter.add("ユーザーID:" + userName + "\r\n" + "tweet:" + tweet); } Status s = homeTl.get(homeTl.size()); Paging p = new Paging(); p.setMaxId(s.getId()); homeTl = null; homeTl = tw.getHomeTimeline(p); for (Status status : homeTl) { // つぶやきのユーザーIDの取得 String userName = status.getUser().getScreenName(); // つぶやきの取得 String tweet = status.getText(); adapter.add("ユーザーID:" + userName + "\r\n" + "tweet:" + tweet); } return adapter; } catch (TwitterException e) { e.printStackTrace(); if (e.isCausedByNetworkIssue()) { Toast.makeText(getApplicationContext(), "ネットワークに接続して下さい", Toast.LENGTH_LONG); } else { Toast.makeText(getApplicationContext(), "エラーが発生しました。", Toast.LENGTH_LONG); } } return null; }
public String TweetDisplay(Status status, int num) { String text = ""; text += (num + " " + show.line(show.getByte(String.valueOf(num) + 1)) + "\n"); String user = status.getUser().getName() + " (" + status.getUser().getScreenName() + ")"; text += (user + show.indent(show.getByte(user) + 1) + "\n"); text += (status.getText() + show.indent(show.getByte(status.getText()) + 1) + "\n\n"); String created_at = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(status.getCreatedAt()); String source = status.getSource().replaceAll("<.+?>", ""); text += (created_at + show.indent(show.getByte(created_at) + show.getByte(source)) + source + "\n"); return text; }
public static void main(String[] args) throws TwitterException { // The factory instance is re-useable and thread safe. Twitter twitter = TwitterFactory.getSingleton(); Query query = new Query("ionic2"); QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); } List<Status> statuses = twitter.getUserTimeline("Ionicframework"); System.out.println("Showing Ionicframework timeline."); for (Status status : statuses) { System.out.println(status.getUser().getName() + ":" + status.getText()); } }
public List<String> showReplies(String reply, String sName) { List<String> replyToList = new ArrayList<String>(); String screenName = sName; long replyToId = Long.parseLong(reply); RateLimitationChecker limit = new RateLimitationChecker(twitter); int rateLimit = limit.checkLimitStatusForEndpoint("/statuses/show/:id"); try { while (replyToId > -1) { if (rateLimit > 1) { replyToList.add(String.valueOf(replyToId)); replyToList.add(screenName); Status status = twitter.showStatus(replyToId); String name = status.getUser().getName(); String text = status.getText(); replyToList.add(name); replyToList.add(text); if (status.getInReplyToStatusId() != 0) { replyToId = status.getInReplyToStatusId(); screenName = status.getInReplyToScreenName(); } } } } catch (TwitterException e) { log.debug("Exception why trying to getName of replyToUser", e); } return replyToList; }
private Tweet getTweetObjectFromStatus(Status status) { Tweet tweet = new Tweet(); tweet.setId(Long.toString(status.getId())); tweet.setText(status.getText()); tweet.setCreatedAt(status.getCreatedAt()); tweet.setFavCount(status.getFavoriteCount()); User user = status.getUser(); tweet.setUserId(user.getId()); tweet.setUserName(user.getName()); tweet.setUserScreenName(user.getScreenName()); HashtagEntity[] hashtagEntities = status.getHashtagEntities(); List<String> hashtags = new ArrayList<String>(); for (HashtagEntity hashtagEntity : hashtagEntities) { hashtags.add(hashtagEntity.getText()); } tweet.setHashTags(hashtags.toArray(new String[hashtags.size()])); GeoLocation geoLocation = status.getGeoLocation(); if (geoLocation != null) { double[] coordinates = {geoLocation.getLongitude(), geoLocation.getLatitude()}; tweet.setCoordinates(coordinates); } return tweet; }
/** * Usage: java twitter4j.examples.json.LoadRawJSON * * @param args String[] */ public static void main(String[] args) { try { File[] files = new File("statuses") .listFiles( new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".json"); } }); for (File file : files) { String rawJSON = readFirstLine(file); Status status = TwitterObjectFactory.createStatus(rawJSON); System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } System.exit(0); } catch (IOException ioe) { ioe.printStackTrace(); System.out.println("Failed to store tweets: " + ioe.getMessage()); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
public static void printTweet(Status tweet, boolean isStream) { String time; if (isStream) { time = ""; try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException ie) { ie.printStackTrace(); } } else { time = getTimeForm(tweet) + " "; } System.out.println(SEPARATOR); String uName = tweet.getUser().getScreenName(); String text = tweet.getText(); Integer retweets = tweet.getRetweetCount(); if (tweet.isRetweet()) { Pattern myPattern = Pattern.compile("RT @([^ ]*): (.*)"); Matcher m = myPattern.matcher(text); m.find(); String uRTName = m.group(1); text = m.group(2); System.out.println(time + "@" + uName + ": ретвитнул @" + uRTName + ": " + text); } else { System.out.println(time + "@" + uName + ": " + text + retweetsForm(retweets)); } }
private void addNewTwitterStatus(Status status) { ContentResolver resolver = getContentResolver(); // Make sure status doesn't alraedy exist String where = TwitterStatusContentProvider.KEY_STATUS_ID + " = " + status.getId(); Cursor query = resolver.query(TwitterStatusContentProvider.CONTENT_URI, null, where, null, null); if (query.getCount() == 0) { ContentValues values = new ContentValues(); values.put(TwitterStatusContentProvider.KEY_STATUS_ID, status.getId()); values.put(TwitterStatusContentProvider.KEY_CREATED_AT, status.getCreatedAt().getTime()); values.put(TwitterStatusContentProvider.KEY_STATUS_TEXT, status.getText()); values.put(TwitterStatusContentProvider.KEY_USER_ID, status.getUser().getId()); values.put(TwitterStatusContentProvider.KEY_USER_NAME, status.getUser().getName()); values.put( TwitterStatusContentProvider.KEY_USER_SCREEN_NAME, status.getUser().getScreenName()); values.put( TwitterStatusContentProvider.KEY_USER_IMAGE, status.getUser().getMiniProfileImageURL()); values.put(TwitterStatusContentProvider.KEY_USER_URL, status.getUser().getURL()); values.put(TwitterStatusContentProvider.KEY_LATITUDE, status.getGeoLocation().getLatitude()); values.put( TwitterStatusContentProvider.KEY_LONGITUDE, status.getGeoLocation().getLongitude()); resolver.insert(TwitterStatusContentProvider.CONTENT_URI, values); } query.close(); }
/** getting Places JSON */ protected String doInBackground(String... args) { Log.d("Tweet Text", "> " + args[0]); String status = args[0]; try { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); // Access Token String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, ""); // Access Token Secret String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, ""); AccessToken accessToken = new AccessToken(access_token, access_token_secret); Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken); // Update status twitter4j.Status response = twitter.updateStatus(status); Log.d("Status", "> " + response.getText()); } catch (TwitterException e) { // Error in updating status Log.d("Twitter Update Error", e.getMessage()); } return null; }
protected Void doInBackground(String... args) { String status = args[0]; try { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(consumerKey); builder.setOAuthConsumerSecret(consumerSecret); // Access Token String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, ""); // Access Token Secret String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, ""); AccessToken accessToken = new AccessToken(access_token, access_token_secret); Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken); // Update status StatusUpdate statusUpdate = new StatusUpdate(status); twitter4j.Status response = twitter.updateStatus(statusUpdate); Log.d("Status", response.getText()); } catch (TwitterException e) { Log.d("Failed to post!", e.getMessage()); } return null; }
private static void primeiraTwittada() throws TwitterException, IOException { Twitter twitter = TwitterFactory.getSingleton(); twitter.setOAuthConsumer("HSPokkXFfwsjWwTGy8kfw", "zMNRv0G9kORPiSXcJuPrnWFOBESewPirr8Lf6fRLpA"); RequestToken requestToken = twitter.getOAuthRequestToken(); AccessToken accessToken = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.println("Open the following URL and grant access to your account:"); System.out.println(requestToken.getAuthorizationURL()); System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:"); String pin = br.readLine(); try { if (pin.length() > 0) { accessToken = twitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = twitter.getOAuthAccessToken(); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } } // persist to the accessToken for future reference. storeAccessToken(twitter.verifyCredentials().getId(), accessToken); Status status = twitter.updateStatus("GO GO GO"); System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.exit(0); }
/** * Usage: java twitter4j.examples.tweets.UpdateStatus [text] * * @param args message */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.tweets.UpdateStatus [text]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); try { // get request token. // this will throw IllegalStateException if access token is already available RequestToken requestToken = twitter.getOAuthRequestToken(); System.out.println("Got request token."); System.out.println("Request token: " + requestToken.getToken()); System.out.println("Request token secret: " + requestToken.getTokenSecret()); AccessToken accessToken = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.println("Open the following URL and grant access to your account:"); System.out.println(requestToken.getAuthorizationURL()); System.out.print( "Enter the PIN(if available) and hit enter after you granted access.[PIN]:"); String pin = br.readLine(); try { if (pin.length() > 0) { accessToken = twitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = twitter.getOAuthAccessToken(requestToken); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } } System.out.println("Got access token."); System.out.println("Access token: " + accessToken.getToken()); System.out.println("Access token secret: " + accessToken.getTokenSecret()); } catch (IllegalStateException ie) { // access token is already available, or consumer key/secret is not set. if (!twitter.getAuthorization().isEnabled()) { System.out.println("OAuth consumer key/secret is not set."); System.exit(-1); } } Status status = twitter.updateStatus(args[0]); System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } catch (IOException ioe) { ioe.printStackTrace(); System.out.println("Failed to read the system input."); System.exit(-1); } }
/** * Transforms a twitter4j.Status object into a JSONObject * * @param pStatus a twitter4j.Status object * @return JSONObject */ @SuppressWarnings("unchecked") public static JSONObject getJson(Status pStatus) { JSONObject jsonObj = null; if (pStatus != null) { jsonObj = new JSONObject(); jsonObj.put("createdAt", pStatus.getCreatedAt()); jsonObj.put("id", pStatus.getId()); jsonObj.put("text", pStatus.getText()); jsonObj.put("source", pStatus.getSource()); jsonObj.put("isTruncated", pStatus.isTruncated()); jsonObj.put("inReplyToStatusId", pStatus.getInReplyToStatusId()); jsonObj.put("inReplyToUserId", pStatus.getInReplyToUserId()); jsonObj.put("isFavorited", pStatus.isFavorited()); jsonObj.put("isRetweeted", pStatus.isRetweeted()); jsonObj.put("favoriteCount", pStatus.getFavoriteCount()); jsonObj.put("inReplyToScreenName", pStatus.getInReplyToScreenName()); jsonObj.put("geoLocation", pStatus.getGeoLocation()); jsonObj.put("place", pStatus.getPlace()); jsonObj.put("retweetCount", pStatus.getRetweetCount()); jsonObj.put("isPossiblySensitive", pStatus.isPossiblySensitive()); jsonObj.put("isoLanguageCode", pStatus.getIsoLanguageCode()); jsonObj.put("contributorsIDs", pStatus.getContributors()); jsonObj.put("retweetedStatus", pStatus.getRetweetedStatus()); jsonObj.put("userMentionEntities", pStatus.getUserMentionEntities()); jsonObj.put("urlEntities", pStatus.getURLEntities()); jsonObj.put("hashtagEntities", pStatus.getHashtagEntities()); jsonObj.put("mediaEntities", pStatus.getMediaEntities()); jsonObj.put("currentUserRetweetId", pStatus.getCurrentUserRetweetId()); jsonObj.put("user", pStatus.getUser()); } return jsonObj; }
public static Tweet fromStatus(Status status) { Tweet tweet = new Tweet(); tweet.setUser(fromUser(status.getUser())); if (status.getPlace() != null) { tweet.setLocation(fromPlace(status.getPlace())); } tweet.setTimeOfTweet(status.getCreatedAt().toString()); tweet.setRetweetCount(status.getRetweetCount()); ArrayList<User> lusers = new ArrayList<User>(); String statusText = status.getText(); for (UserMentionEntity entity : status.getUserMentionEntities()) { lusers.add(fromUserMentionEntity(entity)); statusText = stripMentionedUserFromStatus(statusText, entity); } tweet.setMessage(statusText); tweet.setMentioned(lusers.toArray(new User[] {})); return tweet; }
/** * Sends a Tweet via Twitter * * @param tweetTxt the Tweet to send * @return <code>true</code>, if sending the tweet has been successful and <code>false</code> in * all other cases. */ @ActionDoc( text = "Sends a Tweet via Twitter", returns = "<code>true</code>, if sending the tweet has been successful and <code>false</code> in all other cases.") public static boolean sendTweet( @ParamDoc(name = "tweetTxt", text = "the Tweet to send") String tweetTxt) { if (!TwitterActionService.isProperlyConfigured) { logger.debug("Twitter client is not yet configured > execution aborted!"); return false; } if (!isEnabled) { logger.debug("Twitter client is disabled > execution aborted!"); return false; } try { // abbreviate the Tweet to meet the 140 character limit ... tweetTxt = StringUtils.abbreviate(tweetTxt, CHARACTER_LIMIT); // send the Tweet Status status = client.updateStatus(tweetTxt); logger.debug("Successfully sent Tweet '{}'", status.getText()); return true; } catch (TwitterException e) { logger.error( "Failed to send Tweet '" + tweetTxt + "' because of: " + e.getLocalizedMessage()); return false; } }
private void getTweetsFromTwitter() { try { ConfigurationBuilder confbuilder = new ConfigurationBuilder(); confbuilder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); confbuilder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); // Access Token String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, ""); // Access Token Secret String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, ""); AccessToken accessToken = new AccessToken(access_token, access_token_secret); btnLogoutTwitter.setVisibility(View.GONE); btnGetTweets.setVisibility(View.GONE); lblUserName.setVisibility(View.GONE); btnShowOnMap.setVisibility(View.GONE); btnUsers.setVisibility(View.GONE); Twitter twitter = new TwitterFactory(confbuilder.build()).getInstance(accessToken); List<Status> statuses = twitter.getUserTimeline(USER_ID, new Paging(1, 10)); IDs following = twitter.getFriendsIDs(USER_ID); long[] followingList = following.getIDs(); for (int i = 0; i < followingList.length; i++) { Toast.makeText(getApplicationContext(), twitter.showUser(followingList[i]).toString(), 100) .show(); } int count = 0; // Collections.reverse(statuses); // reverse order ArrayList<String> arrayList = new ArrayList<String>(); for (Status status : statuses) { String tweettext = status.getUser().getName() + ":" + status.getText() + "\n (" + status.getCreatedAt().toLocaleString() + ")" + status.getGeoLocation(); arrayList.add(tweettext); // now single tweet is in tweettext } ListView lv = (ListView) findViewById(R.id.storeTweet); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayList); lv.setAdapter(arrayAdapter); } catch (Exception ex) { // failed to fetch tweet } }
/** * Search tweets with the keyword "word" * * @param word : keyword */ public void doSearch(String word) { List<Status> listStatus; listCleanTweets = new ArrayList<Tweet>(); listDirtyTweets = new ArrayList<Tweet>(); try { Query query = new Query(word); query.resultType(ResultType.mixed); query.setLang("fr"); query.count(30); QueryResult result = InterfaceG.twitter.search(query); listStatus = result.getTweets(); for (Status status : listStatus) { Tweet tclean = new Tweet( status.getId(), status.getUser().getName(), cleanTweet(status.getText()), status.getCreatedAt().toString(), -1); listCleanTweets.add(tclean); Tweet tdirty = new Tweet( status.getId(), status.getUser().getName(), status.getText(), status.getCreatedAt().toString(), -1); listDirtyTweets.add(tdirty); } setChanged(); notifyObservers(); } catch (TwitterException te) { System.out.println("doSearch:TwitterExc"); System.out.println(te.getMessage()); System.exit(-1); } catch (IOException e) { System.out.println("doSearch:IOExc"); System.out.println(e.getMessage()); } }
public void search() throws TwitterException { Twitter twitter = TwitterFactory.getSingleton(); Query query = new Query("Cruyff"); QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); } }
public Tweet(Status status) { this.text = status.getText(); this.longitude = status.getGeoLocation().getLongitude(); this.latitude = status.getGeoLocation().getLatitude(); this.userName = status.getUser().getName(); this.userDescription = status.getUser().getDescription(); this.createdAt = status.getCreatedAt().getTime(); this.tweetId = status.getId(); }
private static void twittarAlgo() throws TwitterException { TwitterFactory factory = new TwitterFactory(); AccessToken accessToken = loadAccessToken(); Twitter twitter = factory.getInstance(); twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); twitter.setOAuthAccessToken(accessToken); Status status = twitter.updateStatus("go go go go"); System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.exit(0); }
@Override public View getView(int position, View convertView, ViewGroup parent) { Status status = (Status) this.items.get(position); ViewHolder viewHolder; if (convertView == null) { LayoutInflater layoutInflater = LayoutInflater.from(context); convertView = layoutInflater.inflate(textViewId, null, false); viewHolder = new ViewHolder(); viewHolder.profileImage = (ImageView) convertView.findViewById(R.id.profileImage); viewHolder.authorFullName = (TextView) convertView.findViewById(R.id.authorFullName); viewHolder.authorTwitterHandle = (TextView) convertView.findViewById(R.id.authorTwitterHandle); viewHolder.authorTwitterHandle.setAutoLinkMask(0); viewHolder.tweetText = (TextView) convertView.findViewById(R.id.tweetText); viewHolder.tweetText.setAutoLinkMask(0); viewHolder.retweetAuthor = (TextView) convertView.findViewById(R.id.retweetAuthor); viewHolder.retweetAuthor.setAutoLinkMask(0); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } Picasso.with(context) .load(R.drawable.ic_launcher) .resize(125, 125) .into(viewHolder.profileImage); if (status.isRetweet()) { Picasso.with(context) .load(status.getRetweetedStatus().getUser().getBiggerProfileImageURLHttps()) .resize(125, 125) .into(viewHolder.profileImage); viewHolder.authorFullName.setText(status.getRetweetedStatus().getUser().getName()); viewHolder.authorTwitterHandle.setText( "@" + status.getRetweetedStatus().getUser().getScreenName()); LinkifyWithTwitter.addLinks(viewHolder.authorTwitterHandle, LinkifyWithTwitter.AT_MENTIONS); viewHolder.retweetAuthor.setText("retweeted by @" + status.getUser().getScreenName()); LinkifyWithTwitter.addLinks(viewHolder.retweetAuthor, LinkifyWithTwitter.AT_MENTIONS); } else { Picasso.with(context) .load(status.getUser().getBiggerProfileImageURLHttps()) .resize(125, 125) .into(viewHolder.profileImage); viewHolder.authorFullName.setText(status.getUser().getName()); viewHolder.authorTwitterHandle.setText("@" + status.getUser().getScreenName()); LinkifyWithTwitter.addLinks(viewHolder.authorTwitterHandle, LinkifyWithTwitter.AT_MENTIONS); viewHolder.retweetAuthor.setText(""); } viewHolder.tweetText.setText(status.getText()); LinkifyWithTwitter.addLinks(viewHolder.tweetText, LinkifyWithTwitter.ALL); return convertView; }
public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long id) { Log.d(TAG, "onItemClick"); Status status = twitterApp.adapter.getItem(pos); Intent detailActivity = new Intent(TimelineActivity.this, DetailActivity.class); detailActivity.putExtra("username", status.getUser().getScreenName()); detailActivity.putExtra("post", status.getText()); detailActivity.putExtra( "timesincepost", DateUtils.getRelativeTimeSpanString(status.getCreatedAt().getTime())); this.startActivity(detailActivity); }
private TwitterData[] map(QueryResult twitterData) { TwitterData[] td = new TwitterData[10]; for (int i = 0; i < twitterData.getTweets().size() && i < 10; i++) { Status status = twitterData.getTweets().get(i); td[i] = new TwitterData( "@" + status.getUser().getScreenName(), status.getText(), status.getCreatedAt().toString()); } return td; }
@Override public void onStatus(Status status) { c++; VectorSpace vsm = new VectorSpace(Long.toString(status.getId()), status.getText()); vocabulary.update(vsm.tokens()); hashTables.add(vsm); if (c > 10000) { VectorSpace[] nn = hashTables.get(vsm); System.out.println(nn.length); } }
@Override public void storeData(Status status) throws InterruptedException { BasicDBObject basicObj = new BasicDBObject(); // if(status.getGeoLocation().equals(true)) // if(status.getGeoLocation().getLatitude()!=0.0d) // { if (status.getGeoLocation() != null) { try { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); basicObj.put("user_name", status.getUser().getScreenName()); basicObj.put("retweet_count", status.getRetweetCount()); // basicObj.put("tweet_followers_count", // status.getUser().getFollowersCount()); basicObj.put("source", status.getSource()); // basicObj.put("coordinates",status.getGeoLocation()); basicObj.put("latitude", status.getGeoLocation().getLatitude()); basicObj.put("longitude", status.getGeoLocation().getLongitude()); // UserMentionEntity[] mentioned = // status.getUserMentionEntities(); // basicObj.put("tweet_mentioned_count", mentioned.length); basicObj.put("tweet_ID", status.getId()); basicObj.put("tweet_text", status.getText()); // i++; } catch (Exception e) { System.out.println(e); } try { items.insert(basicObj); } catch (Exception e) { System.out.println("MongoDB Connection Error : " + e.getMessage()); } } // else // throw new InterruptedException(); }
@Override /* method called when new tweet is read*/ /*Here or in a special method in this class the logic for saving displaying result is called*/ public void onStatus(Status arg0) { String tweet = arg0.getText(); String userName = arg0.getUser().getName(); if (checkTweet(tweet)) { _mainPageContainer.ShowTweet(userName + "" + tweet); /*counts the number of tweets for the chosen celeb and displays them*/ tweetCount++; _mainPageContainer.count.setText(Integer.toString(tweetCount) + " number of tweets"); } }