Example usage for twitter4j Twitter getFollowersIDs

List of usage examples for twitter4j Twitter getFollowersIDs

Introduction

In this page you can find the example usage for twitter4j Twitter getFollowersIDs.

Prototype

IDs getFollowersIDs(long userId, long cursor, int count) throws TwitterException;

Source Link

Document

Returns an array of numeric IDs for every user the specified user is followed by.

Usage

From source file:kerguelenpetrel.FriendSomeoneServlet.java

License:Apache License

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    User friend = null;//from w  w  w  .j  a v  a  2s  .  c  om
    resp.setContentType("text/plain; charset=UTF-8");
    try {
        //Get the Twitter object
        Twitter twit = TwitterFactory.getSingleton();

        //Find a friend of a follower to bother
        long[] followerIDs = twit.getFollowersIDs(twit.getId(), cursor, 30).getIDs();

        if (followerIDs.length == 0) {
            resp.getWriter().println("Cannot find any followers \n");
            return;
        }

        //Load the potential victim IDs
        long[] friendIDs = twit.getFollowersIDs(followerIDs[r.nextInt(followerIDs.length)], cursor).getIDs();

        if (friendIDs.length == 0) {
            resp.getWriter().println("Cannot find any followers to bother \n");
            return;
        }

        //Get a new friend
        friend = twit.showUser(friendIDs[r.nextInt(friendIDs.length)]);
        twit.createFriendship(friend.getId());
        resp.getWriter().println("Made a new friend with @" + friend.getScreenName());

        //Write to our new friend
        StatusUpdate status = new StatusUpdate(writeToFriend(friend.getScreenName(), resp));
        twit.updateStatus(status);
        resp.getWriter().println("Tweet posted: " + status.getStatus());
    } catch (TwitterException e) {
        resp.getWriter().println("Problem with Twitter \n");
        e.printStackTrace(resp.getWriter());
    }
}