“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

  • Dude

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

  • http://betravel.be Hamza

    Thanks ;)

  • http://www.jojet.com Joel Hughes

    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

  • Mike

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

  • http://reinforcemedia.com/2009/12/22/twitter-oauth-401-unauthorized-%e2%80%9cfailed-to-validate-oauth-signature-and-token/ Twitter OAuth: “401 Unauthorized” & “Failed to validate oauth signature and token”

    [...] 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 [...]

  • http://twindicate.com Matt Bernier

    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.

  • http://blog.yporti.com/2009/12/chromium-something-bad-happened-to-chrome-bird-while-calling-twitters-api/ Chromium: Something bad happened to Chrome Bird while calling Twitter’s API. » Blog do Yporti
  • thankful

    Saved my ass! Thanks.

  • http://priceoffrustratio.blogspot.com Jose

    Thanks very much man..

  • http://technoreaders.com jigish thakar

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

    thanks once again

  • amal

    thank you sooooo much ,, big help <3

  • http://rbwebdevelopers.co.uk Ryan

    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

  • Wes DeBoer

    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.

  • Noah

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

  • jibin george

    thanks!

  • Lee

    Thanks a lot!!!

  • http://blog.krahoe.at Matthias

    Thank you really much for this hint!

  • http://glyf.it Glyph

    Wowy-zowy! That sucks. What an obscure problem to figure out. Thanks a bunch to whoever did that crazy legwork.

  • Inopia

    Thank you!

    (check your server clock if you run it in virtualbox and suspend the host computer)

  • Freddie

    Thank you very much for this precious post.

    But what if the site is living in another timezone than US?

    Italy, for instance.

    Is one forced to set system time as US-centric?

    Thanks again,

    Freddie

  • http://www.Joomla-Outsource-India.com Joomla Outsource India

    Hello People, thanks for the sharing and it saved our team a lot of time ! thanks for sharing :)

    Keep it up.

  • http://hasan.we4tech.com nhm tanveer hossain khan

    Hi
    thanks a lot :) you saved my day :)

  • blainegarrett

    @Freddie. You know that is a good question. I don’t think that is the case however since there are multiple time zones here in the US. I don’t know the spec offhand, but that has to be somehow figured in when creating the token.

  • Ken

    Thanks again…solved my issue.

  • http://techmindviews.blogspot.com Sunil Manheri

    Thanks dude! I have been struggling with this issue, finally came across your post.

  • scholarsarena

    Alrite, my clock is set to the default LAN time settings as I work in a WORKGROUP at my workplace.
    My PHP settings have a default timezone specified and set to Asia/Calcutta.
    Should I do anything specific, or different, to make my code work? ‘Coz I’m still gettin an error :(

  • Rihan

    thanks man . this helped me a lot!!!!!!

  • Victor Valle

    Thanks! You saved me 1.9 weeks of frustration

  • daniela

    im sorry but i dont know much about pc or anything and i having this problem and i honestly dont know how to fix i try to change the hr but still not working help!

  • http://bitentropy.info Brock

    My app worked a couple weeks ago, now I went to do some more work on it, and it was failing.

    Clock had drifted 20 minutes behind, and now all working again thanks to your post.

  • .NetGuy

    Hi, How do I fix this issue if it a desktop application and on different timezone?

  • dun boy

    ‘siteUrl’ => ‘https://twitter.com/oauth/authorize

    make sure that your URL is correct in the request.

  • faaiq

    HI,
    can i get access token through ajax.
    bcoz i am gettin error
    Failed to validate oauth signature and token

  • http://www.ezeecloud.com Aboo

    Great Man, but why it is depend on time? example if i work on wrong time then i change valid time i will get this issue so how do i fix permanently ?

  • blainegarrett

    It shouldn’t have anything to do with Ajax. Get it working without ajax first and you should be fine.

  • blainegarrett

    I believe it depends on time because the token makes use of a nonce to make sure it is unique and used only once. I believe there is a little bit of flexibility to accommodate for being seconds off. However, I don’t think you can be hours off.
    If your issue IS indeed the time, the permanent fix is to make sure your production machine always has the correct time for its timezone. Depending on your setup, you can use automated sync tools to manage this.

  • http://vineetmaheshwari.com Vineet Maheshwari

    thanks a ton..two days wasted. I won’t have reached to this conclusion.

    i had this new ubuntu machine setup without doing proper time adjustment. It was only 12 hours diff..but that was not making it work..

    thanks !!!

  • Rafael

    On OSX 10.6.6 I just turned the Apple official time (it was on manual) and Kaboom! Everything works fine! Thank you!

  • Jack

    Thanks for sharing this tip! It really made me mad! I spend half a day already. :)

  • c

    Thanks so much!

  • Harry McDonald

    OMG! I’m not actually a developer, but I downloaded the Twitter for Mac app and have been trying to log in, but it kept giving me the same error code! I gave up for a couple of weeks, but you saved my life! THANK YOU!

  • djzuthy

    Thnx a loooooot man !!!!

  • http://blog.mybecks.net/?p=162 Twitter4J OAuth Problem | Becks Blog

    [...] 2h des googlens habe ich nun die Lösung [...]

  • Roger

    Hello!, my server time is set correctly, but the oauth_token is still empty.

    what can i do ??, when i echo the server time it is correctly.

    Sorry about my english!

    Thanks a lot!

  • Arfajwk

    Thanks, that was helpful I was trying to solve this same issue. now it’s fixed : )

  • None

    Thanks

  • Rldesimone

    OMG MUCHAS GRACIAS !!!! For 3 weeks I coulds figure out what was going on !! I check every blog I could, but only this post finally help me. Now I can go back to twitter for mac

  • http://twitter.com/Nurrizki Risvan

    I swear to god that my computer clock is right in my time zone, but the message still pops out.
    I use echofon for firefox, would anybody be so kind to reply to this -__-

  • Kih01111

    goob job

  • Anonymous

    Thank you! This post saved me a lot of time…

  • http://whatstheplot.com/blog/2011/04/28/updating-osx-for-egypts-dst-changes/ whats the plot » updating osx for egypt’s dst changes

    [...] to the Harare time zone.  not my cup of tea.  thinking about manually changing your time?  bad idea if you have a twitter [...]

  • http://jagsnine.tumblr.com/ jagsnine

     graciaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas!!!!(thankkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkks)

  • ayman

     Hello, I have the same problem alhough my date and time are set to be automatic ! can you please help me ? I’m developing an IOS app and using MAC OS for sure

  • Peter

    Thanks a million!

  • Vaishak

    That worked. Saw your name while going through the oauth library written by Abraham. Then I arrived at this page and got the solution to my problem. You are a good omen Blaine!

  • http://twitter.com/jonathanwkelly Jonathan Kelly

    Thanks for the info! I was having this issue, after copying a library that I knew was working on another server, and all that was different was the tokens.

  • Henry Hu

    Thanks a lot! My system date is 1 day off…

  • GlutaMat

    One minute before killing myself, i found your article !

  • Pallopallopallo

    thanks man sooooooooo much

  • Anonymous

    Thank you! This is the exact issue I had and it was driving me bananas.

  • http://twitter.com/pavel_voronin Павел Воронин

    Thanks a lot!

  • http://www.appdoll.com keshnie

    very usefull artice!

  • Ricardo Bittencourt

    Thanks, I got the same bug and I didn’t know the reason.

  • Mdts

    I also develop an application for android, and I have faced same problem.Can you help me??The time on server clock??what is it,I don’t understand

  • http://www.facebook.com/vinicius.ti Vinicius Trindade

    Valeu vei!! 

  • http://pulse.yahoo.com/_OTDMA4MI7YQMXSDQAZOREBOLDM ALA'A

    Thanks a lot man,it has helped me

  • Raj

    That worked, thanks man….

  • http://twitter.com/RobertReiz Robert Reiz

    That is just ridiculous! Why is twitter make it so difficult? The login with facebook is 1000 times easier. 
    Which timezone should I select on my server? There are 3 timezones in the USA. In which timezones are the twitter server located? Any thought? 
    THX. 

blog comments powered by Disqus
line
footer
Copyright © 1997 - 2010 Blaine Garrett All Rights Reserved