How many requests to Twitter API my program consumes

I need some help with Twitter API error

429:Returned in API v1.1 when a request cannot be served due to the application's rate limit having been exhausted for the resource.

I am using twitter4j and I am trying to store my friends' timelines. The thing is that at the point my code hangs (twitter bans me) don't believe I have reached the Rate Limit yet. It is important to understand in order to put properly the wait() or sleep() method.

My code is the following:

ConfigurationBuilder cb = new ConfigurationBuilder();

        TwitterFactory tf = new TwitterFactory(;            
        Twitter twitter;
        twitter = tf.getInstance();         

        Paging paging;
        DateFormat dateformat =  new SimpleDateFormat("yyyy-MM-dd");
        Date date =  new Date();

        Long tweetsinceId=0L;
                long cursor = -1;            
                IDs ids = twitter.getFriendsIDs(cursor);
                long[] id = ids.getIDs();
                ResponseList<User> users = twitter.lookupUsers(id);
                int numoftweets=1;
                int count=0;

                /**************START: Store the friends of the user in the list usernames - The search will be performed only for the accounts included in the list**************************************************************************************/
                for (User user : users) {

                    numoftweets = user.getStatusesCount();
                    userId = user.getId();

                    System.out.println("INSERT INTO userinfo " +
                         "VALUES ("+userId+",'"+user.getName()+"','"+ user.getScreenName()+"','"+dateformat.format(user.getCreatedAt())+"',"+ user.getFavouritesCount()+","+ user.getFollowersCount()
                                   +","+user.getFriendsCount()+",'"+ user.getDescription()+"','"+user.getLocation()+"',null,"+ numoftweets+",'"+ user.getURL()
                                   +"','"+ user.getMiniProfileImageURL()+"',null, null, '"+user.getLang()+"',"+ user.getAccessLevel()+");");


                    int numberofpages = Math.round(numoftweets / 100);
                    for (int j=1;j<=numberofpages;j++){   
                       if (tweetsinceId==0L){
                           paging = new Paging(j, 100); 
                            paging = new Paging(j, 100).maxId(tweetsinceId);
                               List<Status> statusess = twitter.getUserTimeline(userId,paging);                                   
                               for (Status status3 : statusess)
                                       //if (count==600){
                                         //  Thread.sleep(1000);
                                      // }

                                       String tweet = status3.getText();
                                       Boolean isfavourite = status3.isFavorited();                                                                                   
                                       Boolean isretweet = status3.isRetweet();
                                       Boolean isretweetedbyme=status3.isRetweetedByMe();

                                       System.out.println("INSERT INTO tweetinfo " +
                                       "VALUES ("+userId+","+status3.getId()+",'"+tweet+"','"+ dateformat.format(status3.getCreatedAt())
                                                 +"',null,"+ status3.getCurrentUserRetweetId()+",null,null,null,null"
                                                 +",null,"+status3.getRetweetCount()+",null,null,"+ isfavourite+","+isretweet+","+isretweetedbyme+",null,'"+ status3.getSource()+"');");


                                       tweetsinceId = status3.getId();
                               }//end for
                           } //end if                           
                       }//end for
            catch (Exception e) {

         //}catch(SQLException se){
         }catch(Exception e){
            //Handle errors for Class.forName

So, for the above program twitter API denies access when I am receiving second user's tweets. At this point, I have 1 twitter.getFriendsIDs(cursor), 1 twitter.lookupUsers(id) and 2 twitter.getUserTimeline calls to twitter API

Am I counting wrong the number of calls?

Why does Twitter API already reach the rate limit for my application?

I have already read but maybe I have something misunderstood.

Any kind of help is appreciated.


In Twitter 1.1 you want to look at rate_limit_status.

You can supply a call to


You can list and limit the response to any resoruces in the resource GET call

Need Your Help

Google Maps v3: check if point exists in polygon

google-maps google-maps-api-3 polygon

I am looking to find a way of checking if a point exists inside a polygon in Google Maps v3 (JavaScript). I've searched everywhere and the only solutions I have found so far have been to do with ge...