Posting tweets works and then gives 401


I’ve got an app that responds to tweets using rest api calls to I negotiate OAuth fine. I can look at timelines and read tweets.

I can post a tweet or two successfully. And then the exact same call returns a 401: Authorization Required. The tweets can be a minute or two apart, however it is are not returning a rate limit error. This is not returning a 403: unauthorized response. It is almost like my tokens are expiring, however the documentation states that tokens don’t expire.

How can I get my tweets to post?


If you retry the ones that fail, do they succeed a second time? Or will the same status text fail every time? If the same text fails on retry there is probably an issue with the tweet contents and the OAuth signature.

Correct, tokens don’t automatically expire.


That’s it! While I’m testing the tweets use the same text. When I add a nonce it works.

I’m imagining this is to curb spam? Fair enough, but it’s a pain when developing.

At the very least it could give the actual error–that the tweet is rejected due to being a duplicate. This wasted a lot of time. I also notice that the web site gives an error about duplicate tweets, so it’s not like Twitter isn’t clear about this in other cases.


Note that iirc you can’t make two exactly the same oauth requests, do tue the timestamp being a part of the signature. Additionally to this issue, you can’t post two times the same tweet (this is noted in the docs).


There’s also the nonce that changes each time. This was an issue with posting the same tweet twice while testing the code. It would be nice if it gave an error saying why it wasn’t working, instead of a generic authorization error.


It is not very trivial to return a more detailed error.


They do actually return this as an error, on the web site. So they are already aware of it.