0

I am trying to get access token by following url

https://api.twitter.com/oauth/request_token?
oauth_consumer_key=vRtqh0KONqxr1C2knqv2A&
oauth_nonce=0afa694efd3feee68ebc180f3858a9a3&
oauth_signature=QgHBQ8OLBrjgwivzIfe4p9eBtaQ%3D&
oauth_signature_method=HMAC-SHA1&
oauth_timestamp=1328989636&
oauth_version=1.0

But the error is "Failed to validate oauth signature and token". What is wrong with this url??

Korhan Ozturk
  • 11,148
  • 6
  • 36
  • 49
Muhammad Usman
  • 10,426
  • 22
  • 72
  • 107

2 Answers2

3

Is your system time is properly configured???????

0

One of the reason we get this error "Failed to validate OAuth signature and token" is when system time is wrong. Because OAuth request carry system timestamp parameters with it, when the device time is not within the 5 minutes of Twitter's server time, we get "Failed to validate OAuth signature and token".

If this is the reason, and you want it to make work if the system time is wrong also, then there are two ways to make it work:

  1. Make HTTP HEAD request to an endpoint on api.twitter.com -- you'll get a Date HTTP header in the response that indicates the current time understood by Twitter. You would then convert this to epoch time and adjust your oauth_timestamp values by a determined offset.

  2. There's a small iOS library ios-ntp. Use this to get the accurate current time.

    After that set the timestamp of OAuth object in the following method

    - (GTMOAuthAuthentication *)authForTwitter {
    
        GTMOAuthAuthentication *auth = [[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
                    consumerKey:TWITTER_CONSUMER_KEY
                    privateKey:TWITTER_CONSUMER_SECRET];
        [auth setServiceProvider:@"Twitter"];     
        NSDate * currentdate = //GET ACCURATE DATE HERE ;            
        [auth setTimestamp:[NSString stringWithFormat:@"%f",[currentdate timeIntervalSince1970]]];
        return auth;
    }
    

That's it... Happy coding :)

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
  • Please don't use code blocks for _anything_ but, you know, _code_. And especially don't start [suggesting such edits](http://stackoverflow.com/review/suggested-edits/2869632). See e.g. [here](http://meta.gaming.stackexchange.com/q/7437/88) why, btw – Tobias Kienzler Sep 06 '13 at 06:45