Twitter OAuth Loop 401 Error


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){

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 ( 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:


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