Twitter OAuth Loop 401 Error


#1

I’m using the twitter API (v1.1) for an app I’m working on. I’m running a node.js server on EC2 with node-oauth to interface with the API.

At one point in my code I run a loop to quickly to obtain the five latest tweets from a list of users

Pseudo code:

for (user in users){
   oauth.get(https://api.twitter.com/1.1/statuses/user_timeline.json?count=5&user_id=123456)
}

The number of users could be anywhere from 1-30. The code works fine when there are less than twelve users, but starts randomly throwing 401 errors when there are more roughly than twelve users. Sometimes it happens on the 13th API call, sometimes on the 14th or 18th - basically it’s not constant.

 { statusCode: 401, data:'{"request":"\\/1.1\\/statuses\\/user_timeline.json","error":"Not authorized."}' }

I know I’m not maxing out my rate limit (not getting any 429s), and I’m confident the oauth credentials are correct so what’s going on? I’ve heard it could have to do with server timing mismatch but I ran ntpstat on my EC2 instance it and seemed fine:

 synchronised to NTP server (129.6.15.29) at stratum 2 
     time correct to within 86 ms
     polling server every 1024 s

It’s weird cause it’s working, but clunks out when there are over a certain number of people to loop over.

Any clue as to what’s going on here?

Thanks :wink::star2:


#2

Is it consistent about what users get an error? Maybe they are private and you don’t have permission.