I have looked everywhere for a good example of a JQuery ajax call to authenticate a use in Twitter using their OAuth method. I read the instructions several times and this
I had exactly the same issue. After lose a few hours at the twitter developers page i found this:
https://dev.twitter.com/discussions/3454
Basicly you can't get the oauth_token this way on the client side. That's why you are always getting error 401.
There's a solution to avoid server side using the 'xauth' (https://dev.twitter.com/docs/oauth/xauth), but to do so you need to send a detailed message to api@twitter.com to request xAuth privileges.
The purpose of the 3-leggedo OAuth is to get the user authorise your application's access to the his data. You cannot issue programmatically a Request Token and the an Access Token. The Request Token must be authorised by the user via his browser on a different flow before you can exchange it and get an Access Token.