Client error (429)

ios
swift

#1

Hi,

I got client error (429) as mentioned in the link below it’s related to API rate limits:

https://dev.twitter.com/rest/public/rate-limiting

I waited for more than 15 minute and still I’m getting the same error!

This is my code:

   let statusesShowEndpoint = "https://api.twitter.com/1.1/friends/ids.json"
        params = ["screen_name": user]
        request = client.URLRequestWithMethod("GET", URL: statusesShowEndpoint, parameters: params, error: &clientError)
        
        client.sendTwitterRequest(request) { (response, data, connectionError) -> Void in
            
            if connectionError != nil {
                print("Error: \(connectionError)")
            }
            
            guard let myData = data else {
                
                print("error nil")
                return
            }
            
            let json = JSON(data: myData)
            print("json \(json)")
            self.followingIDs = json["ids"].arrayValue.map { $0.intValue}             
        }

Here is the error:

Error: Optional(Error Domain=TwitterAPIErrorDomain Code=88 "Request failed: client error (429)" UserInfo={NSLocalizedFailureReason=Twitter API error : Rate limit exceeded (code 88), TWTRNetworkingStatusCode=429, NSErrorFailingURLKey=https://api.twitter.com/1.1/users/show.json?user_id=109113333, NSLocalizedDescription=Request failed: client error (429)})

Any suggestion?

Thanks.


#2

As this is an API question and not related to Fabric, switching this to the correct forum.


#3

Ok @bonnell thanks but maybe there is an error in my code?


#4

If you’ve waited 15 minutes, and still getting Rate Limit errors - try waiting an extra few seconds longer - but like you said, if you’re waiting more than 15 minutes and still getting errors it could be something else.

I don’t know swift (is that swift?), but if you can get the rate limit http headers, they contain a reset time & remaining calls in every response - those are handy to keep an eye on to avoid hitting the rate limit and wait an appropriate amount of time.

Make sure there’s no other thread or process or something else hitting that endpoint and using up the rate limit at the same time - that’s the only thing i can think of.

Application Only Auth as a “reserve” is another thing you can try: https://dev.twitter.com/rest/public/rate-limiting


#5

@IgorBrigadir Thanks for your reply I solved my problem. I was writing the request in for loop that why I got error 429.