public List<User> getFollowers() throws TwitterException {
   Twitter twitter = getConnection().getTwitter();
   // Twitter twitter = new TwitterFactory().getInstance();
   // Twitter twitter = TwitterFactory.getSingleton();
   long id = twitter.getId();
   return getFollowers(id); // getConnection().getTwitter().getId());
 }
  @Override
  public Maybe<UserRef> check(AuthToken authToken) {
    Preconditions.checkArgument(authToken.isFor(UserNamespace.TWITTER));

    AccessToken token = new AccessToken(authToken.tokenPayload(), authToken.secretPayload());
    Twitter twitter = twitterFactory.getInstance(token);
    try {
      return Maybe.just(
          userRefBuilder.from(String.valueOf(twitter.getId()), UserNamespace.TWITTER));
    } catch (TwitterException e) {
      return Maybe.nothing();
    }
  }
  /**
   * Returns a list of id of the users the configured account follows. Returns null in case of
   * error.
   */
  public ArrayList<Long> getFollowing() {

    ArrayList<Long> following = new ArrayList<Long>();
    try {
      long lCursor = -1;
      IDs friendsIDs = twitter.getFriendsIDs(twitter.getId(), lCursor);
      do {
        for (long i : friendsIDs.getIDs()) {
          following.add(i);
        }
      } while (friendsIDs.hasNext());

      return following;
    } catch (Exception ex) {
      System.err.println("[ERROR] Can't get following users.");
      ex.printStackTrace();
      return null;
    }
  }
  public static void main(String[] args) {
    try {
      ConfigurationBuilder cb = new ConfigurationBuilder();
      cb.setDebugEnabled(true).setOAuthConsumerKey("fSjrQedRpuRcUv3AmzUqkicCR");
      cb.setDebugEnabled(true)
          .setOAuthConsumerSecret("nGY8pyGD1CsYXaBb8SpeqoHHWYHE8pWeNmiR8Kc7UfWK5bJvTe");
      cb.setDebugEnabled(true)
          .setOAuthAccessToken("98946486-yZqWgilcljm4oVkT82euEDTl0UNna7t8R3F9rGEKZ");
      cb.setDebugEnabled(true)
          .setOAuthAccessTokenSecret("4GKOaU5OAksbNRz5rJy8uGxDM7vtzD3mJBCVJ2uU4qyNa");
      TwitterFactory tf = new TwitterFactory(cb.build());
      Twitter twitter = tf.getInstance();

      ArrayList<TwitterUser> users = new ArrayList<>();

      RateLimitStatus followers = twitter.getRateLimitStatus("followers").get("/followers/ids");
      System.out.println("followers " + followers.getRemaining());
      RateLimitStatus following = twitter.getRateLimitStatus("friends").get("/friends/ids");
      System.out.println("following " + following.getRemaining());

      if (followers.getRemaining() < 2 && following.getRemaining() < 2) {
        System.out.println("Durmiendo por aqui...");
        Thread.sleep(900000);
      }
      TwitterUser me = new TwitterUser(twitter);
      me.setUserID(twitter.getId());
      me.setFollowers(); // 1 follower
      me.setFollowings(); // 1 following
      users.add(me);

      for (int i = 0; i < 10; i++) { // 20 requests
        if (followers.getRemaining() < 2 && following.getRemaining() < 2) {
          System.out.println("Durmiendo por aqui... I=" + i);
          Thread.sleep(900000);
        }
        TwitterUser userX = new TwitterUser(me.getFollowers()[i], twitter);
        userX.setFollowers();
        userX.setFollowings();
        users.add(userX);
        for (int j = 0; j < 10; j++) {
          if (followers.getRemaining() < 2 && following.getRemaining() < 2) {
            System.out.println("Durmiendo por aqui... I=" + i + "J=" + j);
            Thread.sleep(900000);
          }
          TwitterUser userX_1 = new TwitterUser(userX.getFollowers()[j], twitter);
          userX_1.setFollowers();
          userX_1.setFollowings();
          users.add(userX_1);
        }
      }

      for (int i = 0; i < 10; i++) { // 20 requests
        if (followers.getRemaining() < 2 && following.getRemaining() < 2) {
          System.out.println("Durmiendo por aqui... I=" + i);
          Thread.sleep(900000);
        }
        TwitterUser userX = new TwitterUser(me.getFollowings()[i], twitter);
        userX.setFollowers();
        userX.setFollowings();
        users.add(userX);
        for (int j = 0; j < 10; j++) {
          if (followers.getRemaining() < 2 && following.getRemaining() < 2) {
            System.out.println("Durmiendo por aqui... I=" + i + "J=" + j);
            Thread.sleep(900000);
          }
          TwitterUser userX_1 = new TwitterUser(userX.getFollowings()[j], twitter);
          userX_1.setFollowers();
          userX_1.setFollowings();
          users.add(userX_1);
        }
      }

      String content = "";
      for (TwitterUser user : users) {
        content += user.toString();
      }
      File file = new File("/users/cbanegas/Desktop/filename.txt");
      if (!file.exists()) {
        file.createNewFile();
      }
      FileWriter fw = new FileWriter(file.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);
      bw.write(content);
      bw.close();
      System.out.println("Done");
    } catch (TwitterException te) {
      Logger.getLogger(TwitterUser.class.getName()).log(Level.SEVERE, null, te);
      System.out.println("twitter basura");
    } catch (IOException ex) {
      Logger.getLogger(TwitterGraph.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InterruptedException ex) {
      Logger.getLogger(TwitterGraph.class.getName()).log(Level.SEVERE, null, ex);
    }
  }