Exemplo n.º 1
0
  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;
  }
Exemplo n.º 2
0
  /**
   * Method to retrieve and store historical tweets by collecting them with their ID.
   *
   * @param tweetIDs The IDs of the tweets that are going to be collected.
   * @param mongoDB A MongoHandler object.
   * @param config A configuration object.
   * @param event The ground truth event for which the tweets that are going to be collected, are
   *     referring to.
   */
  public final void retrieveTweetsById(
      List<String> tweetIDs, MongoHandler mongoDB, Config config, String event) {

    ConfigurationBuilder cb = getAuthorization();
    Twitter twitter = new TwitterFactory(cb.build()).getInstance();

    tweetIDs
        .stream()
        .forEach(
            (item) -> {
              try {
                // Get tweet and all its metadata and store it
                Status status = twitter.showStatus(Long.parseLong(item));
                mongoDB.insertSingleTweetIntoMongoDB(status, event);
              } catch (TwitterException e) {
                PrintUtilities.printErrorMessageln("Failed to retrieve tweet with ID: " + item);
                Logger.getLogger(TweetsRetriever.class.getName()).log(Level.SEVERE, null, e);
              }
            });
  }
Exemplo n.º 3
0
 public Status showStatus(long id) throws TwitterException {
   return twitter.showStatus(id);
 }