Announcement Announcement Module
Collapse
No announcement yet.
spring-social-twitter 1.0.1 and Rate Limit Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring-social-twitter 1.0.1 and Rate Limit

    I've been testing potential behaviour of my app when an authenticated user of twitter is near their rate limit. I'm finding the TwitterTemplate is returning an OperationNotPermittedException rather than an expected RateLimitException.

    Is this normal behaviour?

    At the moment I'm having to wrap my status update call as follows:

    Code:
    try
    {
      twitter.timelineOperations().updateStatus(post);
    }
    catch (OperationNotPermittedException e)
    {
      if (e.getMessage().contains("User is over daily status update limit")) 
      {
        throw new RateLimitExceededException();
      }
    }
    This seems a bif naff... Does anyone have any other suggestions??

    I'm not particularly comfortable with the idea of parsing the message text of an exception to decide whether to rethrow it.

    To give some context to this; if a status update fails, in most cases I plan to throw it away, but for 'rate limit reached, I'll place that message back on a queue for a delayed delivery (determined by the new RateLimitStatus object).

  • #2
    Looks like I'm hitting one of the broken down 'semi hourly' limits of the 1000 updates per day.

    https://support.twitter.com/articles...-and-following

    I managed to send 126 before getting this exception, so perhaps I can only send 125 updates every 3 hours or so...

    The information provided in the RateLimitStatus object doesn't really reflect this which is a shame. I'm not sure how to calculate when to repost the tweet if I hit this limit.

    Comment


    • #3
      spring-social-facebook

      I noticed if I try the same thing with spring-social-facebook, when I hit my application's posting limit for an authenticated user I get the RateLimitExceeded exception rather than OperationNotPermittedException.

      Twitter apparently don't count 'posts' toward the 'rate limit' - probably hence the lack of RateLimitExceeded exception, I'm wondering therefore it there should be a new 'PostLimitExceeded' exception or similar for these types of circumstances?

      Comment


      • #4
        TwitterErrorHandler.class

        I've discovered TwitterErrorHandler does not handle this type of error. Whenever a HttpStatus.FORBIDDEN status code is returned; duplicate status; status too long; and invalid recipient are checked before throwing a general OperationNotPermittedException...

        I'd recommend the error response is also checked for the text "User is over daily status update limit" which will result in a RateLimitExceeded exception being thrown. This will make it consistent with the spring-social-facebook and a distinctly catchable exception.

        Where should I raise a ticket/tracker for this suggestion?

        Comment


        • #5
          Thanks for catching this and pointing it out. I'll certainly look into it.

          In the meantime, here's where you can submit issues for Spring Social Twitter: https://jira.springsource.org/browse/SOCIALTW. Please feel free to open an issue describing this situation and I'll get right on it.

          Comment


          • #6
            Originally posted by habuma View Post
            Thanks for catching this and pointing it out. I'll certainly look into it.

            In the meantime, here's where you can submit issues for Spring Social Twitter: https://jira.springsource.org/browse/SOCIALTW. Please feel free to open an issue describing this situation and I'll get right on it.
            Thanks! I've created a ticket at https://jira.springsource.org/browse/SOCIALTW-27

            Comment


            • #7
              This is now fixed and I've already pushed a snapshot build (1.0.2.BUILD-SNAPSHOT) includes the fix.

              I also spent some time looking into how to get rate limit details for this particular case. As you noted RateLimitStatus doesn't include this information, but that's because Twitter doesn't return any useful information in this particular case. Even though I'm getting this error, the "account/rate_limit_status" endpoint indicates that I have not yet exceeded the rate limit. I also examined the response headers, hoping to find some useful information there that might indicate how long before the limit is cleared, but I could find no such information in the headers.

              It's unfortunate that Twitter doesn't seem to give any clues regarding the status of this particular rate limit, as that information would (at very least) be useful in documentation or possibly as data attached to the RateLimitExceededException.

              If you discover a way to get stats on this kind of rate limit, please let me know and I'll see if I can work it in.

              Comment


              • #8
                Thanks, I'll download the snapshot and use that.

                The posting limit seems a bit of a black art with Twitter, I read somewhere on the dev site they reduce the posting limits to shape traffic depending on the load on the site.

                I also read that a 'post' does not reduce the number of api calls you are allowed, yet each time I got a failed tweet, the rate limit started decreasing each time. Although interestingly, the time to resume was exactly 1 hour after I originally met my posting limit, but sadly does not correspond to when I can start posting again!

                If I encounter a solution I will definitely add it here.

                Thanks again!

                Comment

                Working...
                X