401 errors when getting the rate limit using 1.1 - works fine with 1.0


#1

Using 1.0 and oAuth, all is working fine using:

https://api.twitter.com/1/account/rate_limit_status.json

but i get 401 errors when attempting:to get rate limits with 1.1:

https://api.twitter.com/1.1/application/rate_limit_status.json?resources=help,users,search,statuses

Any advice on what might be causing this problem? I’m guessing it’s oauth related but the oauth works fine in 1.0.


#2

I would validate that your commas are being encoded correctly in this request. We’re a little lenient with commas, but it’s still possible that your OAuth library or programming language’s URL encode function either under-escapes or over-escapes commas. Here’s a functional example of your request, along with a signature base string to detail the encoding:

URL:

https://api.twitter.com:443/1.1/application/rate_limit_status.json?resources=help%2Cusers%2Csearch%2Cstatuses

Signature base string:

GET&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fapplication%2Frate_limit_status.json&oauth_consumer_key%3D5aA6oofBOFAwN4tfmEYWjg%26oauth_nonce%3DNFccZ3B7yn5n3GjqrqYbQVRVb4PzZ2tqwt33OH8Ok%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1348158438%26oauth_token%3D119476949-oYGCs2M5duG5QalbOAK2YUZh8zG3ur7DPYo5qIFN%26oauth_version%3D1.0%26resources%3Dhelp%252Cusers%252Csearch%252Cstatuses


#3

Yes, the commas appear to be fine. I tried using precisely using the url you provided and I get the same result (401). However, if I go back https://api.twitter.com/1/account/rate_limit_status.json without any other changes, i do get a rate limit without an error.


#4

Are you sure that when you call account/rate_limit_status from 1.0 that you aren’t just being evaluated in an unauthenticated context? (That method supports unauthenticated requests as well, and if you’re auth is faulty you may get it in that context).


#5

I don’t think so because when I started using oauth, rate limits went up from 150 to 300.


#6

One thing I noticed different in the base string is that your oauth_nonce string was longer than mine. The rest was identical.


#7

that rate limit increase should have read 350 and not 300. That is, when I implemented oauth in my application, the rate limit increased to 350 from 150 or whatever it was before.


#8

The nonce shouldn’t be effecting it.

Have you tried leveraging the OAuth tool built into the site and seeing if the curl command it generates works for you? If it does, try to recreate the exact same request in your code and see if you can “train” your code to work for this. Happy to look at a capture of a failed request to see if I can spot any gotchas.


#9

curl works. I’m not sure how to provide a capture of a failed request?


#10

It will depend on your programming environment – different libraries make it easier or harder to capture the raw HTTP of the request in action.

So now you have an example that functions for you with your own keys – if you use the same exact timestamp, nonce, and keys for the successful request in your code, you should be able to build a request that looks exactly the same. Once you can reproduce the exact same request, then try it with a recent timestamp and a new nonce.

Make sure that you’re not sending authorization in multiple ways (mixing query string and auth headers for example).


#11

strange. I made no changes to my code and now it’s suddenly working. Not sure why the rate limit is only 15 but I’m sure that isn’t for the whole hour anymore.


#12

I now have the rate limit working fine in 1.1 but I can’t get search tweets to work without 401 errors. The curl works fine. I’m generating a basestring like the tool gave me or at least I think i am but it’s not clear to me how to now diagnose the 401 error I’m getting. Can you give me some ideas what I should do next to try to fix this problem?