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(); }
@Override public void nextTuple() { // emit tweets Status status = statuses.poll(); if (status == null) Utils.sleep(1000); else { ResponseList<User> followers; ResponseList<User> friends; try { Thread.sleep(6000); followers = twitter.getFollowersList(status.getUser().getScreenName(), -1); Thread.sleep(6000); friends = twitter.getFriendsList(status.getUser().getScreenName(), -1); if (!followers.isEmpty() && !friends.isEmpty()) { spoutOutputCollector.emit(new Values(status, followers, friends)); } // followers.clear(); // friends.clear(); } catch (TwitterException ex) { ex.printStackTrace(); } catch (InterruptedException ex) { ex.printStackTrace(); } } }
private String[] getStatusCreatorIdentifiers(Status status) { String[] identifiers = new String[3]; identifiers[0] = String.valueOf(status.getUser().getId()); identifiers[1] = status.getUser().getScreenName(); identifiers[2] = status.getUser().getName(); return identifiers; }
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 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; }
@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 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 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)); } }
/** * 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 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 } }
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; }
/** * 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 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()); } } }
@Override public void onStatus(Status status) { User user = status.getUser(); // gets Username String username = status.getUser().getScreenName(); System.out.println(username); String profileLocation = user.getLocation(); System.out.println(profileLocation); long tweetId = status.getId(); System.out.println(tweetId); String content = status.getText(); System.out.println(content + "\n"); executor.execute(new Worker(username, id, content, schema)); }
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; }
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; }
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; }
@Override public void onBindViewHolder(RecyclerView.ViewHolder vHolder, int position) { TweetHolder holder = (TweetHolder) vHolder; Status tweet = mTweets.get(position); // Async image loading ImageLoader.getInstance() .displayImage( tweet.getUser().getOriginalProfileImageURL(), holder.imageTweet, MainActivity.sDisplayImageLoaderOptions); holder.textName.setText(tweet.getUser().getName()); holder.textDate.setText(MainActivity.sDateFormat.format(tweet.getCreatedAt())); holder.textDescription.setText(tweet.getText()); }
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()); } }
@Override public void callbackMethod(Status status) { // TODO 自動生成されたメソッド・スタブ if (status.isRetweet()) { System.out.println( color.text_color( ReTweetDisplay( status.getRetweetedStatus(), status.getUser(), Streaming.statues.size() - 1), "blue")); } else { if (status.getUser().getId() == twitter.user_id) { System.out.println( color.text_color(TweetDisplay(status, Streaming.statues.size() - 1), "cyan")); } else { System.out.println(TweetDisplay(status, Streaming.statues.size() - 1)); } } }
@Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Status status = (Status) value; jLabel1.setText("@" + status.getUser().getScreenName()); jLabel3.setText(status.getCreatedAt() + ""); jTextField1.setText(status.getText()); // AVATAR URL urlIMG = null; try { urlIMG = new URL(status.getUser().getProfileImageURL()); } catch (MalformedURLException ex) { Logger.getLogger(Panel_Tweets.class.getName()).log(Level.SEVERE, null, ex); } ImageIcon img = new ImageIcon(urlIMG); jLabel2.setIcon(img); return this; }
protected static ListItem toListItem(Status tweet) { ListItem item1 = new ListItem(); item1.image = defaultImage; item1.id = tweet.getId(); item1.screenName = tweet.getUser().getScreenName(); item1.name = tweet.getUser().getName(); item1.comment = tweet.getText(); item1.geoLocation = tweet.getGeoLocation(); item1.profileImageURL = tweet.getUser().getProfileImageURL().toString(); item1.date = diffDate(tweet.getCreatedAt()); // item1.source = tweet.getSource(); return item1; }
public static void insertRetweet(Status status) throws SQLException { try { PreparedStatement insertRetweetStmt = SqlHelper.getInsertRetweetStmt(); insertRetweetStmt.setLong(1, status.getRetweetedStatus().getId()); insertRetweetStmt.setLong(2, status.getUser().getId()); insertRetweetStmt.setTimestamp(3, new Timestamp(status.getCreatedAt().getTime())); insertRetweetStmt.executeUpdate(); } catch (MySQLIntegrityConstraintViolationException e) { // ignore, this is just a duplicate tweet entry, that's rather normal } }
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 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(); }
public void onStatus(Status status) { String username = status.getUser().getScreenName(); String userLocale = status.getUser().getLocation(); String message = status.getText(); Date timestamp = status.getCreatedAt(); UserMentionEntity[] userMentions = status.getUserMentionEntities(); List<String> userMentionList = new ArrayList<String>(); for (int i = 0; i < userMentions.length; i++) { UserMentionEntity e = userMentions[i]; userMentionList.add(e.getScreenName()); } TwitterEvent event = new TwitterEvent(timestamp, message, username, userLocale, userMentionList); // System.out.println(message + "---------" ); CepEngine.getInstance().addEvent(event); }