“Failed to validate oauth signature and token” on Twitter Oauth – Check Your Clock!

twitter_256x256I have been doing a bit of Twitter development for work in the last few months. Twitter is the first time I have worked with OAuth and it was a bit to wrap my head around. I wanted to tinker around doing some of my own apps since it seems pretty easy now. However, my first attempt at getting it going was a headache. Long story short, if you are unable to get your Request Token, check to make sure your system clock is accurate.

Using the same community libraries I used for work, I would consistently get a 401:Unauthorized – “Failed to validate oauth signature and token”. This seemed odd since my code is really only about 3 lines and the libraries do the rest and everything worked fine at work. Thus, I thought maybe it was my Python installation, but that was up today. Even the Twitter Dev team said that it was rare to have a Request Token fail.

I spent about 2 weeks tearing apart the libraries and checking every step of the process. I contacted the Twitter Dev team to see if my server was somehow blacklisted. Finally, yesterday via the The Twitter Development Google group, someone posted this message.  The gist of it was that a 3rd party dev team was having issues getting the request token and traced it back to their server’s system time being 3 days off. So, I pinged my host guy. As it turns out, he didn’t have the time sync enabled in ubuntu and the clock was 2 hours off. As soon as he enabled sync, my code worked. Derf.

So yup, if you hit the unlikely case that your Request token doesn’t validate, check your system clock. Google Juice, help spread the word.

failboat_arrival

  1. Dude says:

    Thanks for this post. I was also banging my head on this problem and a `ntpdate pool.ntp.org` did wonders!

  2. Joel Hughes says:

    doh!

    Thanks Blaine, I too was banging my head against a wall with this. The sample code is pretty simple so it just didn’t make sense.

    thanks!

    Joel

  3. Mike says:

    ha, so glad this article exists. could have wasted so many more days. google, can we get some more juice?

  4. [...] I went back to Google and searched for this error. One of the first results was, “Failed to validate oauth signature and token” on Twitter Oauth – Check Your Clock! My first thought, “Ah [...]

  5. Matt Bernier says:

    I spend 2 days going over and over through my code trying to figure out what could possibly be the issue with my code. I then submitted multiple support requests to Twitter with either no response, immediately closed tickets, and lots of frustration.
    Upon an extensive search, I found this post and had my problem fixed in less than 3 minutes.
    Thank you so very much for posting this information.

  6. thankful says:

    Saved my ass! Thanks.

  7. Jose says:

    Thanks very much man..

  8. thanks a ton, you solved my problem.. my project is going live today and this was the problem on my server

    thanks once again

  9. amal says:

    thank you sooooo much ,, big help <3

  10. Ryan says:

    Luckily I found this post, my win7 date was out by a day, set the date and time correctly and what do you know it fixes it, check both your date and time, thanks for the usefull post!!

    Ryan

  11. Wes DeBoer says:

    I ran into the same issue on various servers but with identical (rsync’d) code on other servers it worked fine.

    The difference I noted was the PHP version in my case. Working servers were 5.3 and non-working servers were still 5.2. The difference between the two is that PHP 5.2 encodes the ‘~’ into ‘%7E’ but PHP 5.3 now considers it safe and leaves it as is.

    My callback url had a ~ in it therefore generating the request with PHP 5.2 encoding it would result in a mismatch with twitter and would fail.

    Hope this helps anyone that comes across this page like I did searching for answers and the date solution doesn’t help.

  12. Noah says:

    THANK YOU! Almost a year later and your blog post is still saving people from ripping their hair out!

  13. jibin george says:

    thanks!

  14. Lee says:

    Thanks a lot!!!

line
footer
Copyright © 1997 - 2010 Blaine Garrett All Rights Reserved