Failed to validate OAuth signature and token


#1

I am using following code to handle twitter integration in my Application.

GTMOAuthAuthentication *auth = [self authForTwitter];
[auth setCallback:@“http://www.noop.com/OAuthCallback”];

GTMOAuthViewControllerTouch *viewController;
viewController = [[GTMOAuthViewControllerTouch alloc] initWithScope:scope
language:nil
requestTokenURL:requestURL
authorizeTokenURL:authorizeURL
accessTokenURL:accessURL
authentication:auth
appServiceName:@"CK12: Twitter"
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
}

  • (GTMOAuthAuthentication *)authForTwitter {

GTMOAuthAuthentication *auth = [[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
consumerKey:TWITTER_CONSUMER_KEY
privateKey:TWITTER_CONSUMER_SECRET];

[auth setServiceProvider:@“Twitter”];

return auth;
}
My problem is, if I am changing device time i.e making it 1 hour late, then I am getting following error:

Error Domain=com.google.HTTPStatus Code=401 and error message is : failed to validate oauth signature and token .
So can anybody please suggest how to solve this. if system time is wrong then also I want to make it work .


#2

You won’t be able to sign your requests if the system time is incorrect. You’ll need to adjust the system’s clock or the oauth_timestamp value you use to make it correct. One way to do this is to use NTP on the system. Another approach is to make a 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. You wouldn’t want to sync a clock like this more than once every few hours, so you’d also want to find a way to persist this adjustment.


#3

Thank you for reply . . . i am very new to this twitter integration and I don’t know how to request for date header . can you please share some code for requesting date HTTP Header from twitter server in ios. . .